Hi Alexandre,
Now found the third problem (sorry, should have sent the message all
at once) -- Play's OAuth2 sends the authorization request as a GET,
but Google expects a POST or PUT, and OAuth2 does not expect the JSon
response that Google sends back.
I've included (crappy! non-error checking!) code as an example (PS I'm
using Scala, hope you understand it)
val GOOGLE = new OAuth2(
"
https://accounts.google.com/o/oauth2/auth",
"
https://accounts.google.com/o/oauth2/token",
"CLIENT_ID",
"CLIENT_SECRET"
) {
/**
* Need to override this method to add Google-specific scope
parameter
*/
override def retrieveVerificationCode( callbackURL : String ) =
{
import play.mvc.results.Redirect
throw new Redirect(authorizationURL
+ "?client_id=" + clientid
+ "&redirect_uri=" + callbackURL
+ "&scope=
https://www.googleapis.com/auth/userinfo
%23email"
+ "&response_type=code")
}
/**
* Need to override this for Google-specific parameters and
responses
*/
def retrieveJsonAccessToken( callbackURL : String ) : String = {
import play.mvc.Scope.Params
val accessCode = Params.current().get("code")
val params = new java.util.HashMap[String,Object]
params.put("client_id",clientid)
params.put("client_secret",secret)
params.put("redirect_uri",callbackURL)
params.put("code",accessCode)
params.put("grant_type","authorization_code")
WS.url(accessTokenURL).params(params).post.getJson.getAsJsonObject.get("access_token").getAsString
> I've *almost* managed to getOAuth2with Google to work. You'll need