-
Notifications
You must be signed in to change notification settings - Fork 343
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
Error Acquiring Token - MsalServiceException: AADB2C90146 #550
Comments
the Azure AD V2 endpoint allow you to get a token for only one resource at once, however, you can let the user pre-consent for several resources. Please see How to get consent for several resources. My impression is that you have two resources here:
therefore you should use an override of AcquireTokenAsync which has the For instance: string[] scopesForCustomerApi = new string[]
{
"https://myb2c.onmicrosoft.com/customerapi/customer.read",
"https://myb2c.onmicrosoft.com/customerapi/customer.write"
};
string[] scopesForVendorApi = new string[]
{
"https://myb2c.onmicrosoft.com/vendorapi/vendor.read",
"https://myb2c.onmicrosoft.com/vendorapi/vendor.write"
};
var result = await app.AcquireTokenAsync(scopesForCustomerApi,
app.Users.FirstOrDefault(),
uiBehavior,
string.Empty,
scopesForVendorApi); This will get you an access token for the first Web API. |
@stumpykilo closing this as I believe I've answered. Feel free to reopen if you still experience the issue after doing what I recommended. |
@jmprieur, please re-open. We have exactly the same issue with B2C as OP. What you wrote is right for Azure AD v2. Azure AD v2's authorize endpoint accepts scopes for multiple resources followed by token endpoint calls to get each access token separately. In case of B2C, the same flow will end up with AADB2C90146 error on authorize endpoint (exactly the same exception as OP wrote about). What we found is working is to call AcquireTokenAsync() few times to get each access token separately. When calling it for second time we can set UIBehaviour to Consent or Never to display browser only for a moment without the need to re-enter credentials. How to do it in a better way, so that we can get both access tokens without additional flashes? PS: I know that UIBehaviour.Never would cause to hide the browser on Windows, but we need it to work on mobile platforms as well. |
Thanks for the additional information @pasn |
This problem still persists with MSAL v2.3.0.
Still causes the AADBC90146 error. By the way: The authority parameter may not be empty and is not documented. |
@AlexSchuetz I'd like to understand better what the problem is. Also I don't understand what is not documented? We have many parts of the doc where we document the authority:
Can you please elaborate what you would like to see where? I'd like to help, but need a bit more information. |
@jmprieur Unfortunatly I may not share the whole project: Initializing AuthenticationClient:
The following request works as expected: AuthenticationPage is shown and after selecting the user I receive an AuthenticationResult with an AccessToken:
However this request causes the AADBC90146 error. (firstAccount being NULL)
I just noticed, that the two scopes already differ in the host in contrast to your example. I will make a test with same hostnames and post my results. Concerning the documentation: Acquiring tokens interactively Sorry for posting this here, as I don't know how to report this exactly. |
I now verified, that the hostname in the scopes is not the cause of this issue. Here is the exception message:
|
I'm having exactly the same issue as @pasn and @stumpykilo :( Any developments on this? |
@AlexSchuetz @dustynl The limitation is that you cannot ask a token with scopes mixing Web apis in one call. This is a limitation of the service (AAD), not of the library. What shoud we do to improve this document? How to get consent for several resources |
@jmprieur I didn't try to get a token for both apis in one call, but to ask a token for To improve the mentioned document there are two things:
As mentioned above, I tried it with
|
Thanks for clarifying, @AlexSchuetz. I had lost the context that this was B2C. I'll update the docs |
@jmprieur and @AlexSchuetz you need to make individual calls separately to the authorize endpoint for getting tokens to different API's. Did you try that or did you run into problems there too? We do not support user consent (only admin consent). |
Thanks @parakhj for clarifying. So the extraScopesToConsent probably does not make sense in B2C (as it's about user consent). I've updated the wiki page. |
@jmprieur, is there any way to get access token from different applications without prompting the user login again in B2C? |
You can check up my previous comment. I proposed workaround that I was using at a time. It works fine on Windows, but there was screen flickering visible on iOS and Android. Haven't tried it on newer MSAL versions, though. |
@jennyf19, your solution is not working to me. I followed exactly as you said. Let me explain you what exactly I do in my application:
NOTE: DefaultApiScopes are those I always want to authorize the user
Here is accessToken returns Can you please find a fix to it. |
@nkumars Which authority are you using for Also, you might want to try removing |
@jennyf19, in both the method calls, I'm using the below Authority;
I had even tried using a different authority (below) with no luck;
I then tried to follow you, removing
I then later tried removing
|
@nkumars how are you creating the public client? You will need to use string Authority = "https://{tenantId}.b2clogin.com/tfp/{tenant}/{policy}/"
.WithB2CAuthority(B2CConstants.Authority) Which will look like this: PCA = PublicClientApplicationBuilder.Create(B2CConstants.ClientID)
.WithB2CAuthority(B2CConstants.Authority)
.WithRedirectUri($"msal{B2CConstants.ClientID}://auth")
.Build(); and this for the Acquire Token call: IEnumerable<IAccount> accounts = await PCA.GetAccountsAsync();
AuthenticationResult ar = await PCA.AcquireTokenInteractive(B2CConstants.Scopes)
.WithAccount(GetAccountByPolicy(accounts, B2CConstants.PolicyEditProfile))
.WithPrompt(Prompt.NoPrompt)
.WithAuthority(B2CConstants.AuthorityEditProfile) // if you're using a different authority then the one used with the PCA
.WithParentActivityOrWindow(ParentActivityOrWindow)
.ExecuteAsync(); Another idea is to try this B2C sample? You can just switch out all the values here and use your own and see if this works for you. |
I have recently setup a Azure AD BC2 with two web apis and one native application. I can successfully use the Microsoft.Identity.Client nuget package in a legacy Windows Forms app and get authorization to call one of my apis. When I configure the second api with its appropriate .read and .write scopes I get this error (I've replaced my actual tenant domain with myb2c):
Any ideas on what I'm doing wrong or what I need to do do instead?
The text was updated successfully, but these errors were encountered: