renanivo / authoritarian
支持多种授权流程的PHP OAuth 2 客户端
0.0.3
2013-11-19 19:47 UTC
Requires
- guzzle/guzzle: ~3.5
Requires (Dev)
- apigen/apigen: *
- behat/behat: 2.4.*@stable
- behat/mink-extension: *
- behat/mink-selenium2-driver: *
- henrikbjorn/phpspec-code-coverage: dev-master
- phpspec/phpspec: 2.0.*@dev
This package is not auto-updated.
Last update: 2024-09-24 02:03:30 UTC
README
支持多种授权流程的PHP OAuth 2 客户端
安装
获取 composer 并执行
php composer.phar require renanivo/authoritarian
用法
只需设置您的流程并请求访问令牌
客户端凭证流程
<?php use Authoritarian\OAuth2; use Authoritarian\Flow\ClientCredentialsFlow; $flow = new ClientCredentialsFlow(); $flow->setClientCredential('client id', 'client secret'); $oauth2 = new OAuth2('http://example.com/oauth/token'); $token = $oauth2->requestAccessToken($flow)->json();
授权码流程
在登录页面
<?php use Authoritarian\OAuth2; use Authoritarian\Flow\AuthorizationCodeFlow; $flow = new AuthorizationCodeFlow(); $flow->setAuthorizationUrl('http://example.com/oauth/authorize'); $flow->setClientCredential('client id', 'client secret'); $flow->setRedirectUri('http://example.com/callback'); header('Location: ' . $flow->getAuthUrl());
在回调页面
<?php use Authoritarian\OAuth2; use Authoritarian\Flow\AuthorizationCodeFlow; $flow = new AuthorizationCodeFlow(); $flow->setClientCredential('client id', 'client secret'); $flow->setCode($_GET['code']); $oauth2 = new OAuth2('http://example.com/oauth/token'); $token = $oauth2->requestAccessToken($flow)->json();
资源所有者密码
<?php use Authoritarian\OAuth2; use Authoritarian\Flow\ResourceOwnerPasswordFlow; $flow = new ResourceOwnerPasswordFlow( 'username', 'password' ); $flow->setClientCredential('client id', 'client secret'); $oauth2 = new OAuth2('http://example.com/oauth/token'); $token = $oauth2->requestAccessToken($flow)->json();
生成文档
-
下载 apigen.phar
curl -sS http://apigen.org/installer | php -
运行 ApiGen
php apigen.phar generate