Skip to content

Commit c8dcda1

Browse files
authored
fix: TICKET 0009386: Use Microsoft OAuth 2.0 API v2 (#380)
https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration Co-authored-by: atisne <aurelien.tisne@cs-soprasteria.com>
1 parent 94d11dc commit c8dcda1

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

cfg/oauth_samples/oauth.azuread.inc.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@
3636
$tlCfg->OAuthServers['azuread']['oauth_client_secret'] =
3737
'CHANGE_WITH_CLIENT_SECRET';
3838

39+
// https://login.microsoftonline.com/YOUR_TENANT_ID/v2.0/.well-known/openid-configuration
3940
$azureADBaseURL = 'https://login.microsoftonline.com/CHANGE_WITH_TENANT_ID';
41+
$msGraphURL = 'https://graph.microsoft.com';
4042
$tlCfg->OAuthServers['azuread']['oauth_url'] =
41-
$azureADBaseURL . '/oauth2/authorize';
43+
$azureADBaseURL . '/oauth2/v2.0/authorize';
4244

4345
$tlCfg->OAuthServers['azuread']['token_url'] =
44-
$azureADBaseURL . '/oauth2/token';
46+
$azureADBaseURL . '/oauth2/v2.0/token';
4547

4648
$tlCfg->OAuthServers['azuread']['oauth_profile'] =
47-
$azureADBaseURL . '/openid/userinfo';
49+
$msGraphURL . '/oidc/userinfo';
4850

4951

5052
$tlCfg->OAuthServers['azuread']['oauth_enabled'] = true;

lib/functions/oauth_providers/azuread.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
// Get token
1515
function oauth_get_token($authCfg, $code) {
16-
1716
$result = new stdClass();
1817
$result->status = array('status' => tl::OK, 'msg' => null);
1918

@@ -48,7 +47,7 @@ function oauth_get_token($authCfg, $code) {
4847
'Content-Type: application/json',
4948
'Authorization: Bearer ' . $tokenInfo['access_token']
5049
];
51-
curl_setopt($graph_curl, CURLOPT_URL, 'https://graph.microsoft.com/v1.0/me');
50+
curl_setopt($graph_curl, CURLOPT_URL, $authCfg['oauth_profile']);
5251
curl_setopt($graph_curl, CURLOPT_HTTPHEADER, $graph_api_header);
5352
curl_setopt($graph_curl, CURLOPT_RETURNTRANSFER, true);
5453
curl_setopt($graph_curl, CURLOPT_SSL_VERIFYPEER, false);
@@ -65,7 +64,7 @@ function oauth_get_token($authCfg, $code) {
6564

6665
if (isset($jwtInfo['oid'])){
6766
if (isset($authCfg['oauth_domain'])) {
68-
$domain = substr(strrchr($userInfo['userPrincipalName'], "@"), 1);
67+
$domain = substr(strrchr($userInfo['email'], "@"), 1);
6968
if ($domain !== $authCfg['oauth_domain']){
7069
$result->status['msg'] =
7170
"TestLink Oauth policy - User email domain:$domain does not
@@ -79,9 +78,9 @@ function oauth_get_token($authCfg, $code) {
7978
}
8079

8180
$options = new stdClass();
82-
$options->givenName = $userInfo['givenName'];
83-
$options->familyName = $userInfo['surname'];
84-
$options->user = $userInfo['userPrincipalName'];
81+
$options->givenName = $userInfo['given_name'];
82+
$options->familyName = $userInfo['family_name'];
83+
$options->user = $userInfo['email'];
8584
$options->auth = 'oauth';
8685

8786
$result->options = $options;
@@ -91,4 +90,4 @@ function oauth_get_token($authCfg, $code) {
9190
}
9291

9392
return $result;
94-
}
93+
}

0 commit comments

Comments
 (0)