Hi @Roman ,
Thanks for reaching out.
I understand you are trying to retrieve access tokens with multiple scopes.
Unfortunately, this can't be achieved as you can't mix the resources. The access token is issued according to the API audience which identifies the intended recipient of the token you want to access, and this should be unique.
The Microsoft identity platform does not allow you to get a token for several resources at once.
When using the Microsoft Authentication Library for .NET (MSAL.NET), the scopes parameter in the acquire token method should only contain scopes for a single resource. However, you can pre-consent to several resources upfront by specifying additional scopes using the .WithExtraScopeToConsent
builder method.
This will get you an access token for the first web API. Then, to access the second web API you can silently acquire the token from the token cache.
string[] scopesForCustomerApi = new string[]
{
"https://mytenant.onmicrosoft.com/customerapi/customer.read",
"https://mytenant.onmicrosoft.com/customerapi/customer.write"
};
string[] scopesForVendorApi = new string[]
{
"https://mytenant.onmicrosoft.com/vendorapi/vendor.read",
"https://mytenant.onmicrosoft.com/vendorapi/vendor.write"
};
var accounts = await app.GetAccountsAsync();
var result = await app.AcquireTokenInteractive(scopesForCustomerApi)
.WithAccount(accounts.FirstOrDefault())
.WithExtraScopeToConsent(scopesForVendorApi)
.ExecuteAsync();
Hope this will help.
Thanks,
Shweta
Please remember to "Accept Answer" if answer helped you.