From 33ad57d5bb0d34d685f2538e2997059c1d6ef8ee Mon Sep 17 00:00:00 2001 From: Lars Veelaert Date: Tue, 4 Jun 2024 13:15:04 +0200 Subject: [PATCH] Allow host parameter to be configurable to support government tenants To support all Microsoft tenants, this value needs to be configurable: E.g. Microsoft Entra ID for US Government -https://login.microsoftonline.us Microsoft Entra China operated by 21Vianet - https://login.partner.microsoftonline.cn Microsoft Entra ID (global service) -https://login.microsoftonline.com --- src/Auth.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index 156ea77..d2db90b 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -6,7 +6,7 @@ class Auth { - protected $host = 'https://login.microsoftonline.com/'; + protected $host; protected $resource = 'https://graph.microsoft.com/'; protected $tenant_id; protected $client_id; @@ -16,19 +16,23 @@ class Auth protected $guzzle; protected $accessToken; protected $refreshToken; + public function __construct( string $tenant_id, string $client_id, string $client_secret, string $redirect_uri, array $scopes = [], - bool $sslVerify = true + bool $sslVerify = true, + string $host = 'https://login.microsoftonline.com/' ) { $this->tenant_id = $tenant_id; $this->client_id = $client_id; $this->client_secret = $client_secret; $this->redirect_uri = $redirect_uri; $this->scopes = $scopes; + $this->host = $host; + Session::set('host', $this->host); Session::set('resource', $this->resource); Session::set('tenant_id', $tenant_id); @@ -36,9 +40,11 @@ public function __construct( Session::set('client_secret', $client_secret); Session::set('redirect_uri', $redirect_uri); Session::set('scopes', $scopes); + if (!Session::get('state')) { Session::set('state', random_int(1, 200000)); } + $this->guzzle = new \GuzzleHttp\Client([ 'verify' => $sslVerify, ]);