most-significant-bit/oauth2-client

OAuth 2.0 客户端。实现RFC 6749。

0.3.0 2015-11-03 17:27 UTC

This package is not auto-updated.

Last update: 2024-09-20 21:32:26 UTC


README

Build Status

使用方法

use MostSignificantBit\OAuth2\Client\Client as OAuth2Client;
use MostSignificantBit\OAuth2\Client\Config\Config;
use MostSignificantBit\OAuth2\Client\AccessToken\SuccessfulResponse as AccessTokenSuccessfulResponse;
use MostSignificantBit\OAuth2\Client\Grant\ResourceOwnerPasswordCredentials\AccessTokenRequest;
use MostSignificantBit\OAuth2\Client\Grant\ResourceOwnerPasswordCredentials\ResourceOwnerPasswordCredentialsGrant;
use MostSignificantBit\OAuth2\Client\Parameter\AccessToken;
use MostSignificantBit\OAuth2\Client\Parameter\ExpiresIn;
use MostSignificantBit\OAuth2\Client\Parameter\Password;
use MostSignificantBit\OAuth2\Client\Parameter\RefreshToken;
use MostSignificantBit\OAuth2\Client\Parameter\TokenType;
use MostSignificantBit\OAuth2\Client\Parameter\Username;

$config = new Config(array(
    'endpoint' => array(
        'token_endpoint_uri' => 'http://127.0.0.1:8000/oauth2/token',
    ),
    'client' => array(
        'credentials' => array(
            'client_id' => 's6BhdRkqt3',
            'client_secret' => '7Fjfp0ZBr1KtDRbnfVdmIw',
        ),
    ),
));

$oauth2Client = new OAuth2Client($config);

$accessTokenRequest = new AccessTokenRequest(new Username('johndoe'), new Password('A3ddj3w'));

$grant = new ResourceOwnerPasswordCredentialsGrant($accessTokenRequest);

try {
    $accessTokenResponse = $oauth2Client->obtainAccessToken($grant);
} catch (TokenException $exception) {
    //log exception
}

贡献

测试

OAuth2 客户端库已编写单元和集成测试。我们使用phpunit进行这两种测试。

运行所有测试

vendor/bin/phpunit

仅运行单元测试

vendor/bin/phpunit --group unit

仅运行集成测试

vendor/bin/phpunit --group integration