t2v / play2-auth

Play2.x Authentication and Authorization module
Apache License 2.0
608 stars 138 forks source link

Facebook authenticator not working #193

Open hpolkowski opened 6 years ago

hpolkowski commented 6 years ago

I came across a problem with Facebook authenticator.

Error log:

[ERROR] from controllers.FacebookAuthController in application-akka.actor.default-dispatcher-11 - Failed to retrieve access token. {"access_token":"EAADn...SUu","token_type":"bearer","expires_in":5183538}
jp.t2v.lab.play2.auth.social.core.AccessTokenRetrievalFailedException: Failed to retrieve access token. {"access_token":"EAADn...SUu","token_type":"bearer","expires_in":5183538}
    at jp.t2v.lab.play2.auth.social.providers.facebook.FacebookAuthenticator.parseAccessTokenResponse(FacebookAuthenticator.scala:68)
    at jp.t2v.lab.play2.auth.social.providers.facebook.FacebookAuthenticator$$anonfun$retrieveAccessToken$1.apply(FacebookAuthenticator.scala:42)
    at jp.t2v.lab.play2.auth.social.providers.facebook.FacebookAuthenticator$$anonfun$retrieveAccessToken$1.apply(FacebookAuthenticator.scala:40)
Caused by: scala.MatchError: List({"access_token":"EAADn...SUu","token_type":"bearer","expires_in":5183538}) (of class scala.collection.immutable.$colon$colon)
    at jp.t2v.lab.play2.auth.social.providers.facebook.FacebookAuthenticator$$anonfun$parseAccessTokenResponse$2.apply(FacebookAuthenticator.scala:59)
    at jp.t2v.lab.play2.auth.social.providers.facebook.FacebookAuthenticator$$anonfun$parseAccessTokenResponse$2.apply(FacebookAuthenticator.scala:58)

The problem is that FacebookAuthenticator.scala:59 is decoding response wrong.

params <- response.body.split("&").toList
key :: value :: Nil = params.split("=").toList
if key == "access_token"

The code above is trying to decode this response body in json format:

{"access_token":"EAADn...SUu","token_type":"bearer","expires_in":5182252}