1818import  com .github .scribejava .apis .TwitterApi ;
1919import  com .github .scribejava .apis .FacebookApi ;
2020import  com .github .scribejava .apis .GoogleApi20 ;
21+ import  com .github .scribejava .apis .GitHubApi ;
2122
2223public  class  OAuthManagerProviders  {
2324  private  static  final  String  TAG  = "OAuthManagerProviders" ;
@@ -43,6 +44,8 @@ static public OAuth20Service getApiFor20Provider(
4344      return  OAuthManagerProviders .facebookService (params , callbackUrl );
4445    } else  if  (providerName .equalsIgnoreCase ("google" )) {
4546      return  OAuthManagerProviders .googleService (params , callbackUrl );
47+     } else  if  (providerName .equalsIgnoreCase ("github" )) {
48+       return  OAuthManagerProviders .githubService (params , callbackUrl );
4649    } else  {
4750      return  null ;
4851    }
@@ -113,4 +116,34 @@ private static OAuth20Service googleService(final HashMap cfg, final String call
113116
114117    return  builder .build (GoogleApi20 .instance ());
115118  }
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+   }
116149}
0 commit comments