【问题标题】:How to migrate from Oauth1 to Oauth2?如何从 Oauth1 迁移到 Oauth2?
【发布时间】:2013-12-05 13:09:45
【问题描述】:

我一直按照迁移教程中的步骤进行操作:

https://developers.google.com/accounts/docs/OAuth_ref#migration

我正在发送正确的“身份验证”标头,但我得到的只是:

{ "error" : "invalid_token" }

Oauth 令牌有效,我可以从我的应用程序访问 GData 服务就好了。

这是我的迁移代码(简化):

com.google.gdata.client.authn.oauth.OAuthParameters oauthParameters = new com.google.gdata.client.authn.oauth.OAuthParameters();
com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer signer = new com.google.gdata.client.authn.oauth.OAuthHmacSha1Signer();
oauthParameters.setOAuthConsumerKey(oauthConsumerKey);
oauthParameters.setOAuthConsumerSecret(oauthConsumerSecret);
oauthParameters.setOAuthToken(account.getOAuthToken());
oauthParameters.setOAuthTokenSecret(account.getOAuthTokenSecret());
OAuthHelper oauthHelper = new GoogleOAuthHelper(signer);
String header = authHelper.getAuthorizationHeader("http://www.sharedgroups.com", "POST", oauthParameters);
HTTPRequest request = new HTTPRequest(new URL("https://accounts.google.com/o/oauth2/token"), HTTPMethod.POST);
String clientId = "<myid>.apps.googleusercontent.com";
String clientSecret = "<mysecret>";
String payload = "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Amigration%3Aoauth1&client_id="+clientId+"&client_secret="+clientSecret;
request.addHeader(new HTTPHeader("Authorization", header));
request.setPayload(payload.getBytes());
URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService();
HTTPResponse response = urlFetchService.fetch(request);
resp.getWriter().println("RESPONSE="+new String(response.getContent()));

【问题讨论】:

  • 感谢您报告问题。我现在正在研究这个,会尽快更新这个帖子。

标签: oauth google-api google-oauth


【解决方案1】:

我们对 OAuth1->OAuth2 令牌迁移的验证部分进行了一些更改。您介意再次检查您的迁移流程并使用结果更新此线程吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 1970-01-01
    相关资源
    最近更新 更多