【问题标题】:Zend Framework OAuth $_GET parametersZend Framework OAuth $_GET 参数
【发布时间】:2012-11-07 17:14:20
【问题描述】:

目标:创建一个 Oauth Provider 以在 Zend Framework Web 应用程序中使用。

到目前为止的流程:将 Zend Framework OAuth 客户端 (ZF 1.12) 与 Google Code OAuth 类 [http://code.google.com/p/oauth/] 集成。 ZF Client 用作 www 站点中的客户端,Google Code OAuth 用于 api 站点中的身份验证包装器。

寻求帮助以使解决方案发挥作用。

该解决方案适用于基本请求 - 除非 URL 中有 GET 参数,然后两个框架将生成不同的签名,从而破坏身份验证。

示例代码 www:

$uri = 'http://oauth.example.com/search?q=something';

$Application = array();
$Application['oauth_consumer_key'] = 'app';
$Application['oauth_consumer_secret'] = 'appsecret';

$token = new Zend_Oauth_Token_Access();

$config = array(
    'consumerKey' => $Application['oauth_consumer_key'],
    'consumerSecret' => $Application['oauth_consumer_secret'],
);

$client = $token->getHttpClient($config);
$client->setUri($uri);
$client->setMethod(Zend_Http_Client::POST);
$client->setHeaders('Content-Type', 'application/json');
$response = $client->request();

示例代码api:

require_once 'OAuth.php';

$userRequest = OAuthRequest::from_request(null, null, null);
$params = $userRequest->get_parameters();
$params['user_request'] = $userRequest;
$request = $params;

$application = array(
    'token' => 'app',
    'secret' => 'appsecret',
);

// Test OAuth tokens
$oauthConsumer = new OAuthConsumer($application['token'], $application['secret']);
$oauthToken = null;
$signatureMethod = new OAuthSignatureMethod_HMAC_SHA1();

$signature = $signatureMethod->build_signature(
    $request['user_request'],
    $oauthConsumer,
    $oauthToken
);

// If signatures match, return true
if ($request['oauth_signature'] == $signature) {
    return true;
}

return false;

似乎 Zend_Oauth_Token_Access 忽略了自定义参数(参见上面的 '?q='),其中 oauth 类考虑了所有参数。这意味着当没有参数时,两个系统都会生成相同的签名。

我似乎无法让 Zend Oauth 客户端考虑 GET 参数。

请帮忙?

【问题讨论】:

  • 我应该提一下,我首先尝试创建一个应用程序签名以进行验证。稍后会添加用户签名。

标签: zend-framework oauth oauth-provider oauth-php


【解决方案1】:

ZF1 不包括 oauth 提供程序(oauth 1.0a 或 2)。我找到了一些 oauth 1.0a 提供程序,例如 https://github.com/smalyshev/Zend_OAuth_Provider,但我真的很想在我的应用程序中添加 oauth 2.0 支持。

我最终采用https://github.com/quizlet/oauth2-php 并添加了对Zend_Db_Table 作为存储适配器的支持。这个项目的一些代码很乱,但它是迄今为止我发现的最好的 php oauth2 提供程序。

如果您愿意,我可以在 github 存储库中分享我的代码。

【讨论】:

  • 谢谢,我很快就会研究这个库。也许它会在 Zend Oauth 消费者中表现得更好。
猜你喜欢
  • 2012-11-03
  • 1970-01-01
  • 1970-01-01
  • 2013-09-30
  • 2014-06-15
  • 2011-07-08
  • 2011-02-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多