承接 bybrand/oauth2-bitly 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bybrand/oauth2-bitly

Composer 安装命令:

composer require bybrand/oauth2-bitly

包简介

Bitly Provider for PHP League's OAuth 2.0 Client

README 文档

README

This package provides Bitly OAuth 2.0 support for the PHP League's OAuth 2.0 Client. Work with Bitly API (4). Initially, this module was used for the integration of Bybrand with Bitly and is in production.

Full documentation, can be see in Bitly documentation.

Installation

composer require bybrand/oauth2-bitly

Usage

This is a instruction base to get the token, and in then, to save in your database to future request.

use Bybrand\OAuth2\Client\Provider\Bitly as ProviderBitly;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;

$params = $_GET;

$provider = new ProviderBitly([
    'clientId'     => 'key-id',
    'clientSecret' => 'secret-key',
    'redirectUri'  => 'your-url-redirect'
]);

if (!empty($params['error'])) {
    // Got an error, probably user denied access
    $message = 'Got error: ' . htmlspecialchars($params['error'], ENT_QUOTES, 'UTF-8');

    // Return error.
    echo $message;
}
if (!isset($params['code']) or empty($params['code'])) {
    // If we don't have an authorization code then get one
    $authorizationUrl = $provider->getAuthorizationUrl();

    // Get state and store it to the session
    $_SESSION['oauth2state'] = $provider->getState();

    header('Location: '.$authorizationUrl);
    exit;
// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($params['state']) || ($params['state'] !== $_SESSION['oauth2state'])) {
    unset($_SESSION['oauth2state']);

    // Set error and redirect.
    echo 'Invalid stage';
} else {
    try {
        // Try to get an access token (using the authorization code grant)
        $token = $provider->getAccessToken('authorization_code', [
            'code' => $params['code']
        ]);

        // Retriave a list of Bitly groups.
        // @see http://dev.bitly.com/v4/#operation/getGroups
        $groups = $provider->getResourceOwner($token);
    } catch (IdentityProviderException $e) {
        // Error, HTTP code Status
        // @see http://dev.bitly.com/v4/#section/RESTfulness
    } catch (\Exception $e) {
        // Error, make redirect or message.
    }

    // Use this to interact with an API on the users behalf
    echo $token->getToken();
}

Please, for more information see the PHP League's general usage examples.

Refreshing a Token

Bitly tokens do not expire and do not need to be refreshed.

Testing

bash
$ ./vendor/bin/phpunit

or individual method test, by group.

bash
$ ./vendor/bin/phpunit --group=Bitly.GetBaseAccessTokenUrl

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 4.66k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固