php中oauth开发包,如何使用,php需要设置什么?

超级大笨狼 2012-04-28 11:23:18
php中oauth开发包,如何使用,php需要设置什么?
...全文
205 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
helloDongXiu 2012-04-28
  • 打赏
  • 举报
回复
参考:http://php.net/oauth

$req_url = 'https://fireeagle.yahooapis.com/oauth/request_token';
$authurl = 'https://fireeagle.yahoo.net/oauth/authorize';
$acc_url = 'https://fireeagle.yahooapis.com/oauth/access_token';
$api_url = 'https://fireeagle.yahooapis.com/api/0.1';
$conskey = 'your_consumer_key';
$conssec = 'your_consumer_secret';

session_start();

// In state=1 the next request should include an oauth_token.
// If it doesn't go back to 0
if(!isset($_GET['oauth_token']) && $_SESSION['state']==1) $_SESSION['state'] = 0;
try {
$oauth = new OAuth($conskey,$conssec,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
if(!isset($_GET['oauth_token']) && !$_SESSION['state']) {
$request_token_info = $oauth->getRequestToken($req_url);
$_SESSION['secret'] = $request_token_info['oauth_token_secret'];
$_SESSION['state'] = 1;
header('Location: '.$authurl.'?oauth_token='.$request_token_info['oauth_token']);
exit;
} else if($_SESSION['state']==1) {
$oauth->setToken($_GET['oauth_token'],$_SESSION['secret']);
$access_token_info = $oauth->getAccessToken($acc_url);
$_SESSION['state'] = 2;
$_SESSION['token'] = $access_token_info['oauth_token'];
$_SESSION['secret'] = $access_token_info['oauth_token_secret'];
}
$oauth->setToken($_SESSION['token'],$_SESSION['secret']);
$oauth->fetch("$api_url/user.json");
$json = json_decode($oauth->getLastResponse());
print_r($json);
} catch(OAuthException $E) {
print_r($E);
}
?>
shenopkss 2012-04-28
  • 打赏
  • 举报
回复
需要此文件php_oauth.dll (windows)
放入/bin/php[version]/ext

您需要更改 php.ini 加载 oauth (动态扩展)
extension=php_oauth.dll
qq120848369 2012-04-28
  • 打赏
  • 举报
回复
需要为第三方登录按钮写一个申请request的php并将用户重定向到服务商登录页面,给服务商提供一个URL来跳转回我们的网站(php脚本:接受oauth_token等,并请求access,获取用户信息等,最终给用户呈现登录成功界面)。
<?php namespace OAuth\Common; /**  * @author ieter Hordijk   */ class AutoLoader {     /**      * @var string The namespace prefix for this instance.      */     protected $namespace = '';     /**      * @var string The filesystem prefix to use for this instance      */     protected $path = '';     /**      * Build the instance of the autoloader      *      * @param string $namespace The prefixed namespace this instance will load      * @param string $path      The filesystem path to the root of the namespace      */     public function __construct($namespace, $path)     {         $this->namespace = ltrim($namespace, '\\');         $this->path      = rtrim($path, '/\\') . DIRECTORY_SEPARATOR;     }OAUTH协议为用户资源的授权提供了一个安全的、开放而又简易的标准。同时,任何第三方都可以使用OAUTH认证服务,任何服务提供商都可以实现自身的OAUTH认证服务,因而OAUTH是开放的。业界提供了OAUTH的多种实现如PHP、JavaScript,Java,Ruby等各种语言开发包,大大节约了程序员的时间,因而OAUTH是简易的。互联网很多服务如Open API,很多大公司如Google,Yahoo,Microsoft等都提供了OAUTH认证服务,这些都足以说明OAUTH标准逐渐成为开放资源授权的标准。

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧