-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
B2C does not always issue access token but TokenResponse assumes there is an access token resulting in a JSON parse error #140
Comments
@alex-mason-jdas Acknowledged, I am able to reproduce this error. Discussing possible solutions with the team, will update this issue once we have a ETA for a fix. |
@alex-mason-jdas Can you please share details about the scenario where you are trying to acquire just an Id token and no access token or refresh token? Is there any reason why are not requesting the access/ refresh tokens? |
That is the default behavior of B2C if there is no custom scope requested, so it would be a scenario that is just a sign in scenario (monolithic app perhaps). You can see indication in the provided link. I myself don't really agree with the implementation of B2C and think it ought to always return an access token, but it does not if there is no custom scope meaning that this application does not need to call some other web API resource. As far as refresh token, well that really depends on whether the nature of the application needs a longer life or not, doesn't it? In any case, I think you really need to discuss with the B2C team. I am just reporting the behavior since MSAL4J claims to support B2C and this is kind of a basic error. Perhaps the resolution is on the B2C side but it's one of the two and should not really be put back on the user of MSAL nor B2C. https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-reference-oidc |
@alex-mason-jdas Thanks for expanding. I've had a chance to dig in a bit deeper and chat with the B2C team. They should be returning access tokens on all successful token responses. This is a bug on their end which they are now aware of. We won't make any changes to MSAL. While they fix this problem, you can workaround this issue by including the client id of the application as a scope, which will cause B2C to then return an access token. I will leave this issue open until B2C fixes so if anybody else runs into this they can see the workaround. |
Hi, Thanks for the workaround, it instantly fixed the issue. However, I'd like to suggest mentioning this issue prominently in the README, I downloaded the sample code days ago and and have been looking for errors in my ADD+B2C instance that didn't exist. I have a couple of operational questions:
Thanks |
@psidnell We will add a snippet to the README.
|
Just ran into this exact same issue and have been debugging the MSAL code for hours trying to understand what I'm doing wrong. Finally decided to check the Github Issues tab and I saw this! I'm not providing any scopes beyond "openid profile" (although i noticed under the hood it always adds "offline_access" on top of the ones i specified (which might be a separate bug). Here's an example of what im getting back from the authorization code -> token exchange (I obfuscated my id/refresh tokens and client info for security).
|
this issue also exists when using the MSAL.js 2.0 (https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/lib/msal-browser).
|
I've been struggling to get the msal-b2c-web-sample working for a while due to this issue and even the stated workaround isn't resolving the problem for me.
I've tried every combination of the scopes below (I've temporary disabled the external API scope, which also didn't resolve the issue):
I can see in the debugger that the JSON response object from B2C being parsed does not include an access token, similar to what @bpossolo reported, resulting in the JSON parse exception. I have both ID and Access tokens enabled in the B2C configuration of my client application:
What am I missing that others commenting in this issue seem to overcome? |
Would be interested in the answer too. Having the same issue... |
@inventivejon @cserratore-av include the client application's Client ID in the list of scopes. |
This appears to be expected behavior as it's now documented in Azure B2C.
|
Closing this as it is now documented and is an expected behaviour. |
Using MSAL4J library with B2C can result in a JSON parse error due to an assumption in TokenResponse that doesn't always hold with B2C and that assumption is that an access token is always returned. The refresh token has the same assumption although perhaps that is fine? In the case where MSAL4J is used for a server-side application login that needs no custom scope then no access token is returned and this code should not blow up on that scenario.
https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/dev/src/main/java/com/microsoft/aad/msal4j/TokenResponse.java#L48
final AccessToken accessToken = AccessToken.parse(jsonObject);
final RefreshToken refreshToken = RefreshToken.parse(jsonObject);
The text was updated successfully, but these errors were encountered: