Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Fix #334 for Play 2.4 #346

Open
wants to merge 2 commits into
base: 2.4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package com.feth.play.module.pa.providers.oauth2.facebook;

import java.util.Date;
import java.util.Map;

import com.fasterxml.jackson.databind.JsonNode;
import com.feth.play.module.pa.providers.oauth2.OAuth2AuthInfo;
import com.feth.play.module.pa.providers.oauth2.OAuth2AuthProvider;

import static com.feth.play.module.pa.providers.oauth2.OAuth2AuthProvider.Constants.ACCESS_TOKEN;
import static com.feth.play.module.pa.providers.oauth2.OAuth2AuthProvider.Constants.REFRESH_TOKEN;


public class FacebookAuthInfo extends OAuth2AuthInfo {

/**
*
*
*/
private static final long serialVersionUID = 1L;

private static final String EXPIRES = "expires";
private static final String EXPIRES_IN = "expires_in";

public FacebookAuthInfo(final Map<String, String> m) {
super( m.get(OAuth2AuthProvider.Constants.ACCESS_TOKEN),
new Date().getTime() + Long.parseLong(m.get(EXPIRES)) * 1000,
m.get(OAuth2AuthProvider.Constants.REFRESH_TOKEN));
public FacebookAuthInfo(final JsonNode json) {
super(
json.get(ACCESS_TOKEN).asText(),
new Date().getTime() + json.get(EXPIRES_IN).asLong() * 1000,
json.get(REFRESH_TOKEN) != null ? json.get(REFRESH_TOKEN).asText() : null
);
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.feth.play.module.pa.providers.oauth2.facebook;

import java.net.URI;
import java.util.HashMap;

import java.util.List;
import java.util.Map;


import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;

import org.apache.http.message.BasicNameValuePair;

import play.Application;
Expand Down Expand Up @@ -80,24 +79,21 @@ public String getKey() {
@Override
protected FacebookAuthInfo buildInfo(final WSResponse r)
throws AccessTokenException {

final JsonNode respJson = r.asJson();

if (r.getStatus() >= 400) {
throw new AccessTokenException(r.asJson().get(ERROR).get(MESSAGE).asText());

} else {
final String query = r.getBody();
Logger.debug(query);
final List<NameValuePair> pairs = URLEncodedUtils.parse(
URI.create("/?" + query), "utf-8");
if (pairs.size() < 2) {
throw new AccessTokenException();
}
final Map<String, String> m = new HashMap<String, String>(
pairs.size());
for (final NameValuePair nameValuePair : pairs) {
m.put(nameValuePair.getName(), nameValuePair.getValue());

if (respJson.size() < 2) {
throw new AccessTokenException("At least two values were expected, but got " + respJson.size());
}

return new FacebookAuthInfo(m);
return new FacebookAuthInfo(respJson);
}

}

@Override
Expand Down