From 931914da4282e441837cb5fb7f68184393d8f00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Vysko=C4=8Dil?= Date: Mon, 11 Jan 2021 12:32:38 +0100 Subject: [PATCH] Allow to set some params in list of options in constructor * List of added options: 'scopes', 'defaultEndPointVersion' --- README.md | 6 +++++- src/Provider/Azure.php | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e4200bd..fbf2965 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Provider/Azure.php b/src/Provider/Azure.php index 0836910..d07fdef 100644 --- a/src/Provider/Azure.php +++ b/src/Provider/Azure.php @@ -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/'; @@ -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()); }