AzureAD / azure-activedirectory-library-for-java

MIT License
161 stars 126 forks source link

MSAL Java AcquireToken service is returning invalid access token sometimes in MSAL java web #299

Closed ravitheja07580 closed 4 years ago

ravitheja07580 commented 4 years ago

Dear Team,

We are using MSAL java library in our spring boot application to authorize user and retrieve the access token for a custom web api scope: api://xxxxxxxx/access_as_user. We are using below sample code in our application and made changes accordingly to our application where the user will be redirected to MS login page and then gets to redirected to an end point with authorization code and then use it to retrieve the access token.

https://github.com/Azure-Samples/ms-identity-java-webapp/

When MSAL calls acquireToken service, we are receiving the access token for the above scope which works when calling the web api for the first time or couple of times . If i try after some time calling the same acquireToken service, it still generates the access token but this one doesnt work when calling the web api. Also I noticed the access token length for the not working scenario is small compared to the working access token.

We registered our application in Azure portal as both Web and SPA as initially we tried to retrieve the access token from Angular front end. When we use the access token received from angular MSAL acquireTokenPoup, everytime its works while calling our web api. The only difference between SPA and Web is that in Web we initialize the msal client as confidential application with secret key.

We would like to have your guidance in understanding why the access token retrieved on web MSAL java works only first time or first few times and later on the generated access token doesnt work anymore for a given time period. And then it start working after couple of hours and it repeats.

Thank you.

sangonzal commented 4 years ago

@ravitheja07580 Seems like this is an issue with MSAL - could you open up the issue in the right repository?

Steps to reproduce the error would be helpful in getting the issue resolved in a quick manner. Thanks.