Skip to content

Commit e6ade48

Browse files
authored
Merge pull request #120 from microsoftgraph/dev
Release 2.0.0-RC9
2 parents 36ce190 + e6536ee commit e6ade48

File tree

5 files changed

+73
-8
lines changed

5 files changed

+73
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ To install the `microsoft-graph-core` library with Composer, either run `compose
88
```
99
{
1010
"require": {
11-
"microsoft/microsoft-graph-core": "^2.0.0-RC7"
11+
"microsoft/microsoft-graph-core": "^2.0.0-RC9"
1212
}
1313
}
1414
```

src/Authentication/GraphPhpLeagueAccessTokenProvider.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
namespace Microsoft\Graph\Core\Authentication;
1010

1111

12+
use InvalidArgumentException;
13+
use Microsoft\Graph\Core\NationalCloud;
14+
use Microsoft\Kiota\Authentication\Oauth\ProviderFactory;
1215
use Microsoft\Kiota\Authentication\Oauth\TokenRequestContext;
1316
use Microsoft\Kiota\Authentication\PhpLeagueAccessTokenProvider;
1417

@@ -24,14 +27,40 @@
2427
*/
2528
class GraphPhpLeagueAccessTokenProvider extends PhpLeagueAccessTokenProvider
2629
{
30+
public const NATIONAL_CLOUD_TO_AZURE_AD_ENDPOINT = [
31+
NationalCloud::GLOBAL => 'https://login.microsoftonline.com',
32+
NationalCloud::US_GOV => 'https://login.microsoftonline.us',
33+
NationalCloud::CHINA => 'https://login.chinacloudapi.cn'
34+
];
35+
2736
/**
2837
* @param TokenRequestContext $tokenRequestContext
2938
* @param array<string> $scopes if left empty, it's set to ["https://[graph national cloud host]/.default"] scope
39+
* @param string $nationalCloud Defaults to https://graph.microsoft.com. See
40+
* https://learn.microsoft.com/en-us/graph/deployments
3041
*/
31-
public function __construct(TokenRequestContext $tokenRequestContext, array $scopes = [])
42+
public function __construct(
43+
TokenRequestContext $tokenRequestContext,
44+
array $scopes = [],
45+
string $nationalCloud = NationalCloud::GLOBAL
46+
)
3247
{
33-
$allowedHosts = ["graph.microsoft.com", "graph.microsoft.us", "dod-graph.microsoft.us", "graph.microsoft.de",
34-
"microsoftgraph.chinacloudapi.cn", "canary.graph.microsoft.com"];
35-
parent::__construct($tokenRequestContext, $scopes, $allowedHosts);
48+
$allowedHosts = [
49+
"graph.microsoft.com",
50+
"graph.microsoft.us",
51+
"dod-graph.microsoft.us",
52+
"microsoftgraph.chinacloudapi.cn",
53+
"canary.graph.microsoft.com",
54+
"graph.microsoft-ppe.com"
55+
];
56+
$tokenBaseServiceUrl = self::NATIONAL_CLOUD_TO_AZURE_AD_ENDPOINT[$nationalCloud] ??
57+
self::NATIONAL_CLOUD_TO_AZURE_AD_ENDPOINT[NationalCloud::GLOBAL];
58+
$oauthProvider = ProviderFactory::create(
59+
$tokenRequestContext,
60+
[],
61+
$tokenBaseServiceUrl,
62+
$nationalCloud
63+
);
64+
parent::__construct($tokenRequestContext, $scopes, $allowedHosts, $oauthProvider);
3665
}
3766
}

src/Authentication/GraphPhpLeagueAuthenticationProvider.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Microsoft\Graph\Core\Authentication;
1010

11+
use Microsoft\Graph\Core\NationalCloud;
1112
use Microsoft\Kiota\Abstractions\Authentication\BaseBearerTokenAuthenticationProvider;
1213
use Microsoft\Kiota\Authentication\Oauth\TokenRequestContext;
1314

@@ -23,10 +24,16 @@ class GraphPhpLeagueAuthenticationProvider extends BaseBearerTokenAuthentication
2324
/**
2425
* @param TokenRequestContext $tokenRequestContext
2526
* @param array<string> $scopes defaults to ["https://[graph national cloud host]/.default"] scope
27+
* @param string $nationalCloud defaults to https://graph.microsoft.com. See
28+
* https://learn.microsoft.com/en-us/graph/deployments
2629
*/
27-
public function __construct(TokenRequestContext $tokenRequestContext, array $scopes = [])
30+
public function __construct(
31+
TokenRequestContext $tokenRequestContext,
32+
array $scopes = [],
33+
string $nationalCloud = NationalCloud::GLOBAL
34+
)
2835
{
29-
$accessTokenProvider = new GraphPhpLeagueAccessTokenProvider($tokenRequestContext, $scopes);
36+
$accessTokenProvider = new GraphPhpLeagueAccessTokenProvider($tokenRequestContext, $scopes, $nationalCloud);
3037
parent::__construct($accessTokenProvider);
3138
}
3239
}

src/GraphConstants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class GraphConstants
2525
const REST_ENDPOINT = "https://graph.microsoft.com/";
2626

2727
// Define HTTP request constants
28-
const SDK_VERSION = "2.0.0-RC8";
28+
const SDK_VERSION = "2.0.0-RC9";
2929

3030
// Define error constants
3131
const MAX_PAGE_SIZE = 999;

tests/Authentication/GraphPhpLeagueAccessTokenProviderTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Microsoft\Graph\Core\Test\Authentication;
44

5+
use League\OAuth2\Client\Token\AccessToken;
56
use Microsoft\Graph\Core\Authentication\GraphPhpLeagueAccessTokenProvider;
7+
use Microsoft\Graph\Core\NationalCloud;
68
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext;
79
use PHPUnit\Framework\TestCase;
810

@@ -15,4 +17,31 @@ public function testSuccessfullyInitializesClass(): void
1517
$this->assertNotEmpty($leagueAccessTokenProvider->getAllowedHostsValidator()->getAllowedHosts());
1618
}
1719

20+
public function testTokenServiceDefaultsToAzureADGlobalEndpoint(): void
21+
{
22+
$tokenProvider = new GraphPhpLeagueAccessTokenProvider(
23+
new ClientCredentialContext('tenant', 'client', 'secret'),
24+
[],
25+
'https://canary.microsoft.com'
26+
);
27+
$baseUrl = GraphPhpLeagueAccessTokenProvider::NATIONAL_CLOUD_TO_AZURE_AD_ENDPOINT[NationalCloud::GLOBAL];
28+
$this->assertEquals("$baseUrl/tenant/oauth2/v2.0/token", $tokenProvider->getOauthProvider()->getBaseAccessTokenUrl([]));
29+
$this->assertEquals("$baseUrl/tenant/oauth2/v2.0/authorize", $tokenProvider->getOauthProvider()->getBaseAuthorizationUrl());
30+
}
31+
32+
public function testCorrectOAuthEndpointsSet(): void
33+
{
34+
$tokenProvider = new GraphPhpLeagueAccessTokenProvider(
35+
new ClientCredentialContext('tenant', 'client', 'secret'),
36+
[],
37+
NationalCloud::CHINA
38+
);
39+
$baseUrl = GraphPhpLeagueAccessTokenProvider::NATIONAL_CLOUD_TO_AZURE_AD_ENDPOINT[NationalCloud::CHINA];
40+
$this->assertEquals(NationalCloud::CHINA."/oidc/userinfo", $tokenProvider->getOauthProvider()->getResourceOwnerDetailsUrl(
41+
$this->createMock(AccessToken::class)
42+
));
43+
$this->assertEquals("$baseUrl/tenant/oauth2/v2.0/token", $tokenProvider->getOauthProvider()->getBaseAccessTokenUrl([]));
44+
$this->assertEquals("$baseUrl/tenant/oauth2/v2.0/authorize", $tokenProvider->getOauthProvider()->getBaseAuthorizationUrl());
45+
}
46+
1847
}

0 commit comments

Comments
 (0)