Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix Github API access to no longer use deprecated auth methods#169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
billoneil merged 1 commit intomasterfromf/github-creds
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,6 +18,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import okhttp3.Credentials;
import okhttp3.Dispatcher;
import okhttp3.Interceptor;
import okhttp3.Interceptor.Chain;
Expand DownExpand Up@@ -60,6 +61,15 @@ public static Interceptor getHeaderInterceptor(String name, String value) {
};
}

public static Interceptor basicAuth(String user, String password) {
return (Chain chain) -> {
Request orig = chain.request();
String credential = Credentials.basic(user, password);
Request newRequest = orig.newBuilder().addHeader("Authorization", credential).build();
return chain.proceed(newRequest);
};
}

// {{start:client}}
private static final OkHttpClient client;
static {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,11 +15,13 @@
import com.stubbornjava.common.Json;
import com.stubbornjava.common.Retry;

import okhttp3.Authenticator;
import okhttp3.Credentials;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Interceptor.Chain;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;

public class GitHubApi {
private static final Logger logger = LoggerFactory.getLogger(GitHubApi.class);
Expand DownExpand Up@@ -97,22 +99,10 @@ public GitHubApi build() {
OkHttpClient client = HttpClient.globalClient()
.newBuilder()
.addInterceptor(HttpClient.getHeaderInterceptor("Accept", VERSION_HEADER))
.addInterceptor(GitHubApi.gitHubAuth(clientId, clientSecret, ref))
.addInterceptor(HttpClient.basicAuth(clientId, clientSecret))
.addNetworkInterceptor(HttpClient.getLoggingInterceptor())
.build();
return new GitHubApi(client);
}
}

private static Interceptor gitHubAuth(String clientId, String clientSecret, String ref) {
return (Chain chain) -> {
Request orig = chain.request();
HttpUrl url = orig.url().newBuilder()
.addQueryParameter("client_id", clientId)
.addQueryParameter("client_secret", clientSecret)
.addQueryParameter("ref", ref)
.build();
Request newRequest = orig.newBuilder().url(url).build();
return chain.proceed(newRequest);
};
}
}

[8]ページ先頭

©2009-2025 Movatter.jp