Permalink
Browse files

GitHub Provider

This is an initial provider for GitHub for authentication via the service.

Signed-off-by: Ealden Esto E. Escanan <ealden@gmail.com>
  • Loading branch information...
1 parent 4023b8c commit 8f8e884438a218e1b156eee79f7e52f40e6695c5 Ealden Esto E. Escanan committed with Ealden Esto E. Escanan Nov 30, 2011
@@ -22,11 +22,12 @@
public enum ProviderType {
twitter,
facebook,
- google,
+ google,
yahoo,
linkedin,
foursquare,
userpass,
wordpress,
- myopenid
+ myopenid,
+ github
}
@@ -0,0 +1,49 @@
+/**
+ * Copyright 2011 Ealden Esto E. Escanan (ealden at gmail dot com) - twitter: @ealden
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package securesocial.provider.providers;
+
+import com.google.gson.JsonObject;
+import play.libs.WS;
+import securesocial.provider.OAuth2Provider;
+import securesocial.provider.ProviderType;
+import securesocial.provider.SocialUser;
+
+import java.util.Map;
+
+public class GitHubProvider extends OAuth2Provider {
+ private static final String AUTHENTICATED_USER = "https://api.github.com/user?access_token=%s";
+
+ private static final String LOGIN = "login";
+ private static final String NAME = "name";
+ private static final String PICTURE = "avatar_url";
+ private static final String EMAIL = "email";
+
+ public GitHubProvider() {
+ super(ProviderType.github);
+ }
+
+ @Override
+ protected void fillProfile(SocialUser user, Map<String, Object> authContext) {
+ WS.HttpResponse response = WS.url(AUTHENTICATED_USER, user.accessToken).get();
+ JsonObject authenticatedUser = response.getJson().getAsJsonObject();
+
+ user.id.id = authenticatedUser.get(LOGIN).getAsString();
+ user.displayName = authenticatedUser.get(NAME).getAsString();
+ user.avatarUrl = authenticatedUser.get(PICTURE).getAsString();
+ user.email = authenticatedUser.get(EMAIL).getAsString();
+ }
+}
@@ -69,7 +69,7 @@ h3. Identity Providers
You can customize which identity providers your application uses and the order they appear in the login page as follows:
-bc. securesocial.providers=twitter,facebook,google,yahoo,foursquare,linkedin,wordpress,myopenid,userpass
+bc. securesocial.providers=twitter,facebook,google,yahoo,foursquare,linkedin,wordpress,myopenid,userpass,github
For example if you only wanted to use Twitter, Facebook and Google you would set it as:
@@ -140,6 +140,14 @@ securesocial.foursquare.accessTokenURL=https://foursquare.com/oauth2/access_toke
securesocial.foursquare.clientid=your_client_id
securesocial.foursquare.secret=your_client_secret
+bc. #
+# GitHub
+#
+securesocial.github.authorizationURL=https://github.com/login/oauth/authorize
+securesocial.github.accessTokenURL=https://github.com/login/oauth/access_token
+securesocial.github.clientid=your_client_id
+securesocial.github.secret=your_client_secret
+
Some providers use a scope property. The values shown above are what SecureSocial needs to provide your app with the name, email and avatar of your users. If you need permissions you can add the required scopes in a comma separated list.
If you are going to use the UsernamePassword provider set the following properties that are required by the Mailer:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8f8e884

Please sign in to comment.