-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitHubAuth.java
51 lines (40 loc) · 1.43 KB
/
GitHubAuth.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.company.myapp.lib.github;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;
import org.apache.commons.lang3.StringUtils;
public class GitHubAuth {
public static final String ACCESS_TOKEN_EXTRA = "GitHubAccessToken";
public static String CLIENT_ID;
public static String CLIENT_SECRET;
public static String[] SCOPE;
public static String REDIRECT_URL;
private static GitHubAuthService gitHubAuthService =
new Retrofit.Builder()
.baseUrl("https://github.com/")
.addConverterFactory(ScalarsConverterFactory.create())
.build()
.create(GitHubAuthService.class);
public static void requestAccessToken(String code, Callback<String> callback) {
String scope = null;
if (SCOPE.length > 0) {
scope = StringUtils.join(SCOPE, " ");
}
gitHubAuthService
.postloginoauthaccesstoken(CLIENT_ID, CLIENT_SECRET, scope, code)
.enqueue(callback);
}
private interface GitHubAuthService {
@Headers({"Accept: application/json"})
@POST("login/oauth/access_token")
Call<String> postloginoauthaccesstoken(
@Query("client_id") String clientId,
@Query("client_secret") String clientSecret,
@Query("scope") String scope,
@Query("code") String code);
}
}