1313
1414// Get token
1515function 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