Skip to content

Commit

Permalink
Allow to set some params in list of options in constructor
Browse files Browse the repository at this point in the history
* List of added options: 'scopes', 'defaultEndPointVersion'
  • Loading branch information
vyskocilpavel committed Jan 11, 2021
1 parent fc059d1 commit 931914d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ Usage is the same as The League's OAuth client, using `\TheNetworg\OAuth2\Client
$provider = new TheNetworg\OAuth2\Client\Provider\Azure([
'clientId' => '{azure-client-id}',
'clientSecret' => '{azure-client-secret}',
'redirectUri' => 'https://example.com/callback-url'
'redirectUri' => 'https://example.com/callback-url',
//Optional
'scopes' => 'openid',
//Optional
'defaultEndPointVersion' => '2.0'
]);

// Set to use v2 API, skip the line or set the value to Azure::ENDPOINT_VERSION_1_0 if willing to use v1 API
Expand Down
10 changes: 9 additions & 1 deletion src/Provider/Azure.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Azure extends AbstractProvider
{
const ENDPOINT_VERSION_1_0 = '1.0';
const ENDPOINT_VERSION_2_0 = '2.0';

const ENDPOINT_VERSIONS = [self::ENDPOINT_VERSION_1_0, self::ENDPOINT_VERSION_2_0];

use BearerAuthorizationTrait;

public $urlLogin = 'https://login.microsoftonline.com/';
Expand All @@ -42,6 +43,13 @@ class Azure extends AbstractProvider
public function __construct(array $options = [], array $collaborators = [])
{
parent::__construct($options, $collaborators);
if (isset($options['scopes'])) {
$this->scope = array_merge($options['scopes'], $this->scope);
}
if (isset($options['defaultEndPointVersion']) &&
in_array($options['defaultEndPointVersion'], self::ENDPOINT_VERSIONS, true)) {
$this->defaultEndPointVersion = $options['defaultEndPointVersion'];
}
$this->grantFactory->setGrant('jwt_bearer', new JwtBearer());
}

Expand Down

0 comments on commit 931914d

Please sign in to comment.