Skip to content

Commit

Permalink
Add setting for Facebook user fields to retrieve.
Browse files Browse the repository at this point in the history
Also added FacebookAuthUser.getBirthday().
  • Loading branch information
smola committed Mar 6, 2013
1 parent 5a2e0be commit 729e491
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Expand Up @@ -24,10 +24,12 @@ public class FacebookAuthProvider extends

private static final String MESSAGE = "message";
private static final String ERROR = "error";
private static final String FIELDS = "fields";

static final String PROVIDER_KEY = "facebook";

private static final String USER_INFO_URL_SETTING_KEY = "userInfoUrl";
private static final String USER_INFO_FIELDS_SETTING_KEY = "userInfoFields";

public FacebookAuthProvider(Application app) {
super(app);
Expand All @@ -39,11 +41,14 @@ protected FacebookAuthUser transform(FacebookAuthInfo info, final String state)

final String url = getConfiguration().getString(
USER_INFO_URL_SETTING_KEY);
final String fields = getConfiguration().getString(
USER_INFO_FIELDS_SETTING_KEY);
final Response r = WS
.url(url)
.setQueryParameter(OAuth2AuthProvider.Constants.ACCESS_TOKEN,
info.getAccessToken()).get()
.get(PlayAuthenticate.TIMEOUT);
info.getAccessToken())
.setQueryParameter(FIELDS, fields)
.get().get(PlayAuthenticate.TIMEOUT);

final JsonNode result = r.asJson();
if (result.get(OAuth2AuthProvider.Constants.ERROR) != null) {
Expand Down
Expand Up @@ -31,7 +31,8 @@ private static abstract class Constants {
public static final String TIME_ZONE = "timezone";// 2
public static final String LOCALE = "locale";// "de_DE"
public static final String VERIFIED = "verified";// true
public static final String UPDATE_TIME = "updated_time"; // "2012-04-26T20:22:52+0000"}
public static final String UPDATE_TIME = "updated_time"; // "2012-04-26T20:22:52+0000"
public static final String BIRTHDAY = "birthday"; // "25/12/1980"}
}

private String name;
Expand All @@ -45,6 +46,7 @@ private static abstract class Constants {
private int timezone;
private String locale;
private String updateTime;
private String birthday;

public FacebookAuthUser(final JsonNode node, final FacebookAuthInfo info,
final String state) {
Expand Down Expand Up @@ -83,6 +85,9 @@ public FacebookAuthUser(final JsonNode node, final FacebookAuthInfo info,
if (node.has(Constants.UPDATE_TIME)) {
this.updateTime = node.get(Constants.UPDATE_TIME).asText();
}
if (node.has(Constants.BIRTHDAY)) {
this.birthday = node.get(Constants.BIRTHDAY).asText();
}
}

@Override
Expand Down Expand Up @@ -139,4 +144,9 @@ public Locale getLocale() {
public String getUpdateTime() {
return updateTime;
}

public String getBirthday() {
return birthday;
}

}
8 changes: 7 additions & 1 deletion code/conf/reference.conf
Expand Up @@ -133,6 +133,12 @@ play-authenticate {
authorizationUrl="https://graph.facebook.com/oauth/authorize"
accessTokenUrl="https://graph.facebook.com/oauth/access_token"
userInfoUrl="https://graph.facebook.com/me"

# Comma-separated list of fields to retrieve from this Facebook user.
# See possible values here: https://developers.facebook.com/docs/reference/api/user/
# Note that some fields may require additional permissions on your Facebook App.
userInfoFields="id,name,first_name,middle_name,last_name,link,gender,email,timezone,locale,updated_time"

scope=email

# Get the credentials here: https://developers.facebook.com/apps
Expand Down Expand Up @@ -186,4 +192,4 @@ play-authenticate {
}
}
}
}
}

0 comments on commit 729e491

Please sign in to comment.