psx/oauth2
最新稳定版本:v4.1.0
Composer 安装命令:
composer require psx/oauth2
包简介
OAuth2 consumer
关键字:
README 文档
README
About
This package provides an OAuth2 client implementation and it provides also common DTOs and exceptions to build an OAuth2 server implementation
Usage
Authorization code
<?php // at first for the authorization code flow you need to redirect your user to the OAuth2 server AuthorizationCode::redirect('[auth_url]', '[client_id]', '[redirect_url]'); // if the customer returns you can obtain an access token $client = new \PSX\Http\Client\Client(); $code = new \PSX\OAuth2\Authorization\AuthorizationCode($client, new Url('[token_url]')); $code->setClientPassword('[client_id]', '[client_secret]'); $accessToken = $code->getAccessToken('[redirect_url]'); // if we have an access token we can request the api using the access token $header = [ 'Authorization' => TokenAbstract::factory($accessToken)->getHeader() ]; $request = new GetRequest('[api_url]', $header); $response = $client->request($request); if ($response->getStatusCode() == 200) { // request worked }
Client credentials
<?php $client = new \PSX\Http\Client\Client(); $code = new \PSX\OAuth2\Authorization\ClientCredentials($client, new Url('[token_url]')); $code->setClientPassword('[client_id]', '[client_secret]'); $accessToken = $code->getAccessToken(); // work with the access token
统计信息
- 总下载量: 67.18k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2016-03-31