2011-05-28 113 views
1

我使用OAuth with Federated Login (Hybrid Protocol)来允许我的用户使用openID登录一次(这很好用),并且同时使用Google Data API进行身份验证。使用OpenID + OAuth获取访问令牌和秘密(谷歌)

Zend_GData库让我头痛,所以在这里的人的建议,我切换到LightOpenID

中的OpenID部分的伟大工程,并感谢this提示我能添加的OAuth extenstion和收到这样的回应:

http://www.example.com/checkauth 
?openid.ns=http://specs.openid.net/auth/2.0 
&openid.mode=id_res 
&openid.op_endpoint=https://www.google.com/accounts/o8/ud 
&openid.response_nonce=2009-01-17T00:11:20ZlJAgbeXUfSSSEA 
&openid.return_to=http://www.example.com/checkauth 
&openid.assoc_handle=AOQobUeYs1o3pBTDPsLFdA9AcGKlH 
&openid.signed=op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle,ns.ext2,ext2.consumer,ext2.scope,ext2.request_token 
&openid.sig=oPvRr++f6%2ul/2ah2nOTg= 
&openid.identity=https://www.google.com/accounts/o8/id/id=AItOawl27F2M92ry4jTdjiVx06tuFNA 
&openid.claimed_id=https://www.google.com/accounts/o8/id/id=AItOawl27F2M92ry4jTdjiVx06tuFNA 
&openid.ns.oauth=http://specs.openid.net/extensions/oauth/1.0 
&openid.oauth.scope=http://docs.google.com/feeds/+http://spreadsheets.google.com/feeds/+http://sandbox.gmodules.com/api/ 
&openid.oauth.request_token=1/fVr0jVubFA83GjYUA 

根据该文件,openid.oauth.request_token是授权请求令牌,所以看起来我不需要做OAuthAuthorizeToken请求。目前为止都很好,但现在我需要将此请求令牌交换为访问令牌和令牌密钥。

因为我不知道如何生成OAuth随机数和签名,所以我使用了PHP的OAuthSimple库。但问题是,代码需要看起来像这样:

// Build the request-URL... 
$result = $oauth->sign(array(
    'path' => 'https://www.google.com/accounts/OAuthGetAccessToken', 
    'parameters' => array(
     'oauth_verifier' => $_GET['oauth_verifier'], 
     'oauth_token' => $_GET['oauth_token']), 
    'signatures' => $signatures)); 

它需要一个oauth_verifier值,你会与一个正常的OAuth请求请求令牌收到一起。我不确定是否OAuthSimple库在尝试省略时遇到错误,或者它是Google的要求,但不起作用。

那么,有人可以发现我在这里做错了吗?

回答

0

没有什么错。实际上,当您执行混合进程时,验证者不会发送,只是因为您不需要它。

所以在你的代码中,只要将验证器设置为NULL,并且它应该可以正常工作,只要其他地方没有问题。

相关问题