18
18
import com .github .scribejava .apis .TwitterApi ;
19
19
import com .github .scribejava .apis .FacebookApi ;
20
20
import com .github .scribejava .apis .GoogleApi20 ;
21
+ import com .github .scribejava .apis .GitHubApi ;
21
22
22
23
public class OAuthManagerProviders {
23
24
private static final String TAG = "OAuthManagerProviders" ;
@@ -43,6 +44,8 @@ static public OAuth20Service getApiFor20Provider(
43
44
return OAuthManagerProviders .facebookService (params , callbackUrl );
44
45
} else if (providerName .equalsIgnoreCase ("google" )) {
45
46
return OAuthManagerProviders .googleService (params , callbackUrl );
47
+ } else if (providerName .equalsIgnoreCase ("github" )) {
48
+ return OAuthManagerProviders .githubService (params , callbackUrl );
46
49
} else {
47
50
return null ;
48
51
}
@@ -113,4 +116,34 @@ private static OAuth20Service googleService(final HashMap cfg, final String call
113
116
114
117
return builder .build (GoogleApi20 .instance ());
115
118
}
119
+
120
+ private static OAuth20Service githubService (final HashMap cfg , final String callbackUrl ) {
121
+ String clientKey = (String ) cfg .get ("client_id" );
122
+ String clientSecret = (String ) cfg .get ("client_secret" );
123
+ String state ;
124
+ if (cfg .containsKey ("state" )) {
125
+ state = (String ) cfg .get ("state" );
126
+ } else {
127
+ state = TAG + new Random ().nextInt (999_999 );
128
+ }
129
+ String scope = "profile" ;
130
+ if (cfg .containsKey ("scope" )) {
131
+ scope = (String ) cfg .get ("scope" );
132
+ }
133
+
134
+ ServiceBuilder builder = new ServiceBuilder ()
135
+ .apiKey (clientKey )
136
+ .apiSecret (clientSecret )
137
+ .state (state )
138
+ .scope (scope )
139
+ .debug ();
140
+
141
+ if (callbackUrl != null ) {
142
+ builder .callback (callbackUrl );
143
+ }
144
+
145
+ Log .d (TAG , "builder ---> " + callbackUrl );
146
+
147
+ return builder .build (GitHubApi .instance ());
148
+ }
116
149
}
0 commit comments