项目作者: AlaaSarhan

项目描述 :
Docusign OAuth2 Provider for League OAuth2 Client
高级语言: PHP
项目地址: git://github.com/AlaaSarhan/oauth2-docusign.git
创建时间: 2018-11-04T23:40:11Z
项目社区:https://github.com/AlaaSarhan/oauth2-docusign

开源协议:MIT License

下载


Docusign Provider for OAuth 2.0 Client

Latest Version
Software License
Coverage Status
Quality Score
Total Downloads

This package provides Docusign OAuth 2.0 support for the PHP League’s OAuth 2.0 Client.

Installation

To install, use composer:

  1. composer require sarhan/oauth2-docusign

Usage

Usage is the same as The League’s OAuth client, using \Sarhan\OAuth2\Client\Provider\Docusign as the provider.

Authorization Code Flow

  1. $provider = new \Sarhan\OAuth2\Client\Provider\Docusign([
  2. 'clientId' => '{docusign-integrator-key}',
  3. 'clientSecret' => '{docusign-integrator-key-secret}',
  4. 'redirectUri' => 'https://example.com/callback-url'
  5. ]);
  6. if (!isset($_GET['code'])) {
  7. // If we don't have an authorization code then get one
  8. $authUrl = $provider->getAuthorizationUrl();
  9. $_SESSION['oauth2state'] = $provider->getState();
  10. header('Location: ' . $authUrl);
  11. exit;
  12. // Check given state against previously stored one to mitigate CSRF attack
  13. } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
  14. unset($_SESSION['oauth2state']);
  15. exit('Invalid state');
  16. } else {
  17. // Try to get an access token (using the authorization code grant)
  18. $token = $provider->getAccessToken('authorization_code', [
  19. 'code' => $_GET['code']
  20. ]);
  21. // Optional: Now you have a token you can look up a users profile data
  22. try {
  23. // We got an access token, let's now get the user's details
  24. $user = $provider->getResourceOwner($token);
  25. // Use these details to create a new profile
  26. printf('Hello %s!', $user->getId());
  27. } catch (Exception $e) {
  28. // Failed to get user details
  29. exit('Oh dear...');
  30. }
  31. // Use this to interact with an API on the users behalf
  32. echo $token->getToken();
  33. }

Refreshing a Token

  1. $provider = new \Sarhan\OAuth2\Client\Provider\Docusign([
  2. 'clientId' => '{docusign-integrator-key}',
  3. 'clientSecret' => '{docusign-integrator-key-secret}',
  4. 'redirectUri' => 'https://example.com/callback-url'
  5. ]);
  6. $token = $provider->getAccessToken('refresh_token', [
  7. 'refresh_token' => '{refresh token}'
  8. ]);

Vendor specific options

sandbox

when passed with true to the provider constructor, the provider will direct docuaign endpoint calls to docusign sandbox domain (account-d.docusign.com).

  1. $provider = new \Sarhan\OAuth2\Client\Provider\Docusign([
  2. 'clientId' => '{docusign-integrator-key}',
  3. 'clientSecret' => '{docusign-integrator-key-secret}',
  4. 'redirectUri' => 'https://example.com/callback-url',
  5. 'sandbox' => true
  6. ]);

Testing

  1. $ ./vendor/bin/phpunit

or

  1. $ composer test

Contributing

Please see CONTRIBUTING for details.

License

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