Skip to content

Commit

Permalink
add support for json in buildInfo From request
Browse files Browse the repository at this point in the history
  • Loading branch information
marhw committed May 16, 2017
1 parent af86662 commit 186d0d0
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import play.api.{Application, Logger}
import play.api.libs.json.JsObject
import securesocial.core._
import play.api.libs.ws.{ Response, WS }
import play.api.libs.json._

/**
* A Facebook Provider
Expand All @@ -44,7 +45,20 @@ class FacebookProvider(application: Application) extends OAuth2Provider(applicat

// facebook does not follow the OAuth2 spec :-\
override protected def buildInfo(response: Response): OAuth2Info = {
response.body.split("&|=") match {
try {
buildInfoJson(response.body)
} catch {
case e: Exception => {
buildInfoRaw(response.body)
}
}
}
protected def buildInfoJson(body: String): OAuth2Info = {
val json: JsValue = Json.parse(body)
OAuth2Info((json \ "access_token").as[String], None, (json \ "expires_in").asOpt[Int])
}
protected def buildInfoRaw(body: String): OAuth2Info = {
body.split("&|=") match {
case Array(AccessToken, token, Expires, expiresIn) => OAuth2Info(token, None, Some(expiresIn.toInt))
case Array(AccessToken, token) => OAuth2Info(token)
case _ =>
Expand Down

0 comments on commit 186d0d0

Please sign in to comment.