我正在将 OpenID 2.0 迁移到 OAuth 2.0 登录(请参阅 https://developers.google.com/accounts/docs/OpenID?hl=ja )。我想将新的 OpenID 2.0 标识符映射到数据库中的旧/现有 OpenID Connect 标识符。
我正在处理 OAuth 响应 (redirect_uri),我想在其中使用 https://www.googleapis.com/oauth2/v3/token端点,用于交换访问 token 和 openid_id 字段的授权代码,我将使用它来选择数据库中的现有用户。
但是,我调用https://www.googleapis.com/oauth2/v3/token返回“未找到”。知道为什么吗?
我使用的是 scribe 1.3.7,这是我的代码:
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
对 https://www.googleapis.com/oauth2/v3/token
的请求返回“Not Found”。您需要使用 HTTP POST
进行请求。
将代码的第 3 行更新为以下内容,然后重试:
OAuthRequest request = new OAuthRequest(Verb.POST, "https://www.googleapis.com/oauth2/v3/token");
您可以在 official docs 中阅读有关用代码交换访问 token 和 ID token 的更多信息。 .
关于google-app-engine - OpenId Connect 端点返回 'not found',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28250301/