manishrasrani / ms-adal-angular6

This is a wrapper library for Angular 6+ (Angular 6.X.X and Angular 7.X.X) modules over Microsoft ADAL (Azure Active Directory Authentication Library)
https://www.npmjs.com/package/microsoft-adal-angular6
MIT License
34 stars 13 forks source link

Cannot retrieve authorization code using ms-adal-angular6's sign-in request #19

Open jemeshjoseph opened 5 years ago

jemeshjoseph commented 5 years ago

Using ms-adal-angular6 package, we are not able to get the authorization code from the sign-in request oauth2/authorize. The app can use the authorization code to request an access token for the target resource. The response_type query parameter in the sign-in request is hard-coded to have value 'id_token' only. So in-order to get authorization code, there should be change in response_type parameter value in our sign-in request. The value should be response_type=id_token+code. Thus the request will return your app an authorization code to exchange for an access token.

See the official documentation here https://docs.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-openid-connect-code#get-access-tokens

See the sign-in request sample for more details.

// Line breaks for legibility only

GET https://login.microsoftonline.com/{tenant}/oauth2/authorize?
client_id=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx        // Your registered Application ID
&response_type=id_token+code
&redirect_uri=http%3A%2F%2Flocalhost%3a4200          // Your registered Redirect Uri, url encoded
&response_mode=form_post                              // `form_post' or 'fragment'
&scope=openid
&resource=https%3A%2F%2Fservice.app.com%2F        // The identifier of the protected resource (web API) that your application needs access to
&state=12345                                          // Any value, provided by your app
&nonce=678910                                         // Any value, provided by your app``

It would be better to set the response_type value in our configuration settings and thus we can remove the hard-coded values such as id_token. Do the needful to get the authorization code from the sign-in request.