I am migrating OpenID 2.0 to OAuth 2.0 login (see https://developers.google.com/accounts/docs/OpenID?hl=ja). I want to map the new OpenID 2.0 identifiers to old/existing OpenID Connect identifiers, which I have in my DB.
I'm at the point of handling the OAuth response (redirect_uri), where I want to use the https://www.googleapis.com/oauth2/v3/token endpoint, to exchange the authorization code for an access token and an openid_id field, which I would use to select an existing user in my DB.
However, my call to https://www.googleapis.com/oauth2/v3/token returns 'not found'. Any clue why?
I'm using scribe 1.3.7, and this is my code:
OAuthService service = new ServiceBuilder().provider(Google2Api.class).apiKey(xxxxxxxx).apiSecret(yyyyyyyyyyyyyyy).callback(zzzzzzzzzzzzzzzzzzzz).scope("openid profile https://mail.google.com/ https://www.googleapis.com/auth/userinfo.email").build();
Token accessToken = service.getAccessToken(null, new Verifier(oauth_verifier);
OAuthRequest request = new OAuthRequest(Verb.GET, "https://www.googleapis.com/oauth2/v3/token");
request.addQuerystringParameter("format","json");
request.addQuerystringParameter(OAuthConstants.REALM, "http://*.unclestock.com");
service.signRequest(accessToken, request);
Response response = request.send();
// result -> not found
GET
requests to https://www.googleapis.com/oauth2/v3/token
return 'Not Found'. You need to use HTTP POST
for the request.
Update line 3 of your code to the following, and try it again:
OAuthRequest request = new OAuthRequest(Verb.POST, "https://www.googleapis.com/oauth2/v3/token");
You can read more about exchanging the code for an access token and an ID Token in the official docs.