@@ -18,32 +18,29 @@ class Provider extends AbstractProvider
1818 *
1919 * @var string
2020 */
21- protected $ graphUrl = 'https://graph.windows.net/myorganization /me ' ;
21+ protected $ graphUrl = 'https://graph.microsoft.com/v1.0 /me ' ;
2222
2323 /**
24- * The Graph API version for the request .
24+ * The scopes being requested .
2525 *
26- * @var string
26+ * @var array
2727 */
28- protected $ version = ' 1.5 ' ;
28+ protected $ scopes = [ ' User.Read ' ] ;
2929
3030 /**
3131 * {@inheritdoc}
3232 */
3333 protected function getAuthUrl ($ state )
3434 {
35- return $ this ->buildAuthUrlFromBase (
36- 'https://login.microsoftonline.com/ ' .($ this ->config ['tenant ' ] ?? 'common ' ).'/oauth2/authorize ' ,
37- $ state
38- );
35+ return $ this ->buildAuthUrlFromBase ($ this ->getBaseUrl ().'/oauth2/v2.0/authorize ' , $ state );
3936 }
4037
4138 /**
4239 * {@inheritdoc}
4340 */
4441 protected function getTokenUrl ()
4542 {
46- return ' https://login.microsoftonline.com/common/oauth2 /token ' ;
43+ return $ this -> getBaseUrl (). ' /oauth2/v2.0 /token ' ;
4744 }
4845
4946 public function getAccessToken ($ code )
@@ -63,9 +60,6 @@ public function getAccessToken($code)
6360 protected function getUserByToken ($ token )
6461 {
6562 $ response = $ this ->getHttpClient ()->get ($ this ->graphUrl , [
66- RequestOptions::QUERY => [
67- 'api-version ' => $ this ->version ,
68- ],
6963 RequestOptions::HEADERS => [
7064 'Accept ' => 'application/json ' ,
7165 'Authorization ' => 'Bearer ' .$ token ,
@@ -81,27 +75,45 @@ protected function getUserByToken($token)
8175 protected function mapUserToObject (array $ user )
8276 {
8377 return (new User ())->setRaw ($ user )->map ([
84- 'id ' => $ user ['objectId ' ], 'nickname ' => null , 'name ' => $ user ['displayName ' ],
85- 'email ' => $ user ['userPrincipalName ' ], 'avatar ' => null ,
78+ 'id ' => $ user ['id ' ],
79+ 'nickname ' => null ,
80+ 'name ' => $ user ['displayName ' ],
81+ 'email ' => $ user ['userPrincipalName ' ],
82+ 'avatar ' => null ,
8683 ]);
8784 }
8885
8986 /**
9087 * {@inheritdoc}
9188 */
92- protected function getTokenFields ( $ code )
89+ public static function additionalConfigKeys ( )
9390 {
94- return array_merge (parent ::getTokenFields ($ code ), [
95- 'grant_type ' => 'authorization_code ' ,
96- 'resource ' => 'https://graph.windows.net ' ,
91+ return ['tenant ' , 'logout_url ' , 'proxy ' ];
92+ }
93+
94+ /**
95+ * Get the access token response for the given code.
96+ *
97+ * @param string $code
98+ *
99+ * @return array
100+ */
101+ public function getAccessTokenResponse ($ code )
102+ {
103+ $ response = $ this ->getHttpClient ()->post ($ this ->getTokenUrl (), [
104+ RequestOptions::HEADERS => ['Accept ' => 'application/json ' ],
105+ RequestOptions::FORM_PARAMS => $ this ->getTokenFields ($ code ),
106+ RequestOptions::PROXY => $ this ->getConfig ('proxy ' ),
97107 ]);
108+
109+ return json_decode ($ response ->getBody (), true );
98110 }
99111
100112 /**
101- * {@inheritdoc}
113+ * @return string
102114 */
103- public static function additionalConfigKeys ()
115+ protected function getBaseUrl (): string
104116 {
105- return [ ' tenant '] ;
117+ return ' https://login.microsoftonline.com/ ' . $ this -> getConfig ( ' tenant ', ' common ' ) ;
106118 }
107119}
0 commit comments