@@ -230,25 +230,31 @@ private function exchangeCode() {
230230 // Generate the url to the API that will give us the access token and id token
231231 $ auth_url = $ this ->generateUrl ('token ' );
232232 // Make the call
233- $ auth0_response = $ this ->oauth_client ->getAccessToken ($ auth_url , "authorization_code " , array (
233+ $ response = $ this ->oauth_client ->getAccessToken ($ auth_url , "authorization_code " , array (
234234 "code " => $ code ,
235235 "redirect_uri " => $ this ->redirect_uri
236236 ), array (
237237 'Auth0-Client ' => ApiClient::getInfoHeadersData ()->build ()
238238 ));
239239
240- // Parse it
241- $ auth0_response = $ auth0_response ['result ' ];
240+ $ auth0_response = $ response ['result ' ];
241+
242+ if ($ response ['code ' ] !== 200 ) {
243+ throw new ApiException ($ auth0_response ['error ' ] . ': ' . $ auth0_response ['error_description ' ]);
244+ }
245+
242246 $ this ->debugInfo (json_encode ($ auth0_response ));
243247 $ access_token = (isset ($ auth0_response ['access_token ' ]))? $ auth0_response ['access_token ' ] : false ;
244248 $ id_token = (isset ($ auth0_response ['id_token ' ]))? $ auth0_response ['id_token ' ] : false ;
245249
246250 if (!$ access_token ) {
247251 throw new ApiException ('Invalid access_token - Retry login. ' );
248252 }
249- if (!$ id_token ) {
250- throw new ApiException ('Missing JWT after code exchange. Remember to ask for openid scope. ' );
253+
254+ if (!$ id_token ) { // id_token is not mandatory anymore. There is no need to force openid connect
255+ $ this ->debugInfo ('Missing id_token after code exchange. Remember to ask for openid scope. ' );
251256 }
257+
252258 // Set the access token in the oauth client for future calls to the Auth0 API
253259 $ this ->oauth_client ->setAccessToken ($ access_token );
254260 $ this ->oauth_client ->setAccessTokenType (Client::ACCESS_TOKEN_BEARER );
0 commit comments