谷歌OpenID与OAuth - 如何获取访问令牌

1 投票
1 回答
4212 浏览
提问于 2025-04-16 17:13

我有一个网站,想让用户链接他们的GMail账户,之后我想通过OAuth来访问用户的GMail账户。我使用的是谷歌的OpenID+OAuth(混合协议)来实现这个功能。

当我按照上面提到的文档操作时,我得到了以下内容 -

openid.assoc_handle AOQobUfg8E9PvTYX1huZPleVGoSvky57TxLHMzI-Lxd87cDNwLyrutSm
openid.claimed_id   https://www.google.com/accounts/o8/id?id=AItOawlus8fqLMQGgfCCM6pDZGpuNjwQqqYMs4o
openid.ext1.mode    fetch_response
openid.ext1.type.email  http://axschema.org/contact/email
openid.ext1.value.email forward@gmail.com
**openid.ext2.request_token   4/C-VqYG9lRtJBKM9G15I-tFk58rOS**
openid.ext2.scope   https://mail.google.com/
openid.identity https://www.google.com/accounts/o8/id?id=AItOawlus8fqLMQGgfCCM6pDZGpuNjwQqqYMs4o
openid.mode id_res
openid.ns   http://specs.openid.net/auth/2.0
openid.ns.ext1  http://openid.net/srv/ax/1.0
openid.ns.ext2  http://specs.openid.net/extensions/oauth/1.0
openid.op_endpoint  https://www.google.com/accounts/o8/ud
openid.response_nonce   2011-05-07T18:38:37ZOEVDbKdW6d2g9A
openid.return_to    https://mysite.com/gmail_redir/
openid.sig  niD5l9V7cG+LOE2zYjJ6rS0Cdwc=
openid.signed   op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle,ns.ext1,ns.ext2,ext1.mode,ext1.type.email,ext1.value.email,ext2.scope,ext2.request_token

我得到了openid.ext2.request_token,这个是用来让我通过OAuth访问用户GMail账户的。这个是怎么工作的呢?难道我不需要访问令牌(也就是oauth_access_secret和oauth_access_token)吗?

我还需要再发出其他请求吗?有没有人知道接下来该怎么做??

1 个回答

2

一旦你有了一个令牌(token),你需要:

  1. 先对它进行授权,然后
  2. 把它换成一个访问令牌(access token)

你可以看看这个链接:http://code.google.com/apis/accounts/docs/OAuth.html#WorkingOauth

或者这个链接:https://developers.google.com/accounts/docs/OAuth2(这是关于OAuth v2的)

撰写回答