您好,欢迎访问一九零五行业门户网

PHP扩展—OAuth

一、概述及安装
此扩展提供 oauth 消费方和提供方之间的绑定。oauth 是一种建立在 http 之上的授权协议,用于允许应用程序安全访问数据而无需存储用户名和密码。
pecl/oauth 需要 php 5.1 或更高版本,以及 ext/hash 和 ext/pcre 。
如果在构建时选择 pecl/oauth 则可选择性地需要 libcurl 。如果使用 libcurl 配置,则必须构建 https 支持。
安装此 pecl 扩展相关的信息可在手册中标题为 pecl 扩展的安装章节中找到。
二、使用范例
<?php $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(); // 当 state=1 则下次请求应该包含一个 oauth_token 。 // 如果没有则返回 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); } ?>
三、相关函数
oauth_get_sbs — 生成一个签名字符基串
oauth_urlencode — 将 uri 编码为 rfc 3986 规范
四、相关类及其成员函数
oauth类
oauth::__construct — 新建一个 oauth 对象
oauth::__destruct — 析构函数
oauth::disabledebug — 关闭详细的调试
oauth::disableredirects — 关闭重定向
oauth::disablesslchecks — 关闭 ssl 检查
oauth::enabledebug — 启用详细调试
oauth::enableredirects — 启用重定向
oauth::enablesslchecks — 启用 ssl 检查
oauth::fetch — 获取一个 oauth 受保护的资源
oauth::generatesignature — 生成一个签名
oauth::getaccesstoken — 获取一个访问令牌
oauth::getcapath — 获取 ca 信息
oauth::getlastresponse — 获取最后一次的响应
oauth::getlastresponseheaders — 获取最后一次响应的头信息
oauth::getlastresponseinfo — 获取关于最后一次响应的 http 信息
oauth::getrequestheader — 生成 oauth 头信息字符串签名
oauth::getrequesttoken — 获取一个请求令牌
oauth::setauthtype — 设置授权类型
oauth::setcapath — 设置 ca 路径和信息
oauth::setnonce — 为后续请求设置现时标志
oauth::setrequestengine — 设置目标请求引擎
oauth::setrsacertificate — 设置 rsa 证书
oauth::setsslchecks — 调整特定的ssl请求检查
oauth::settimestamp — 设置时间戳
oauth::settoken — 设置令牌和 secret
oauth::setversion — 设置 oauth 版本
oauthprovider 类
oauthprovider::addrequiredparameter — 添加必需的参数
oauthprovider::callconsumerhandler — 调用 consumernoncehandler 回调函数
oauthprovider::calltimestampnoncehandler — 调用 timestampnoncehandler 回调函数
oauthprovider::calltokenhandler — 调用 tokennoncehandler 回调函数
oauthprovider::checkoauthrequest — 检查一个 oauth 请求
oauthprovider::__construct — 新建一个 oauthprovider 对象
oauthprovider::consumerhandler — 设置 consumerhandler 句柄回调函数
oauthprovider::generatetoken — 生成一个随机令牌
oauthprovider::is2leggedendpoint — is2leggedendpoint
oauthprovider::isrequesttokenendpoint — 设置 isrequesttokenendpoint
oauthprovider::removerequiredparameter — 移除一个必需的参数
oauthprovider::reportproblem — 报告问题
oauthprovider::setparam — 设置一个参数
oauthprovider::setrequesttokenpath — 设置请求令牌路径
oauthprovider::timestampnoncehandler — 设置 timestampnoncehandler 句柄回调函数
oauthprovider::tokenhandler — 设置 tokenhandler 句柄回调函数
oauthexception 类
oauthexception — oauthexception 类
其它类似信息

推荐信息