You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add multiple AAD authentication options using AddMicrosoftIdentityWebAppAuthentication not possible #971
Which version of Microsoft Identity Web are you using?
Microsoft Identity Web 1.6.0
Where is the issue?
Web app
Sign-in users
Sign-in users and call web APIs
Web API
Protected web APIs (validating tokens)
Protected web APIs (validating scopes)
Protected web APIs call downstream web APIs
Token cache serialization
In-memory caches
Session caches
Distributed caches
Other (please describe)
I have an app which needs to support authentication using multiple AAD's, but if I try to call AddMicrosoftIdentityWebAppAuthentication multiple times it seams that only the last one takes affect, but I get a "Unable to unprotect the message.State" exception although I've set different CallbackPath.
If I try to logging using azuread1 it will say the user dows not exist in azuread2.onmicrosoft.com, while if I log in using azuread2 I get an "Unable to unprotect the message.State" exception.
Mikael Håkansson (@wmmihaa) : AddMicrosoftIdentityWebAppAuthentication is a shortcut for the simple case where you don't want to specify the scheme, whereas the multi AAD scenario is the very case where you want to control the scheme.
You'll want to do;
I think the problem is in SignInManager.ConfigureExternalAuthenticationProperties which will always route to the same AAD independently of the provider...
public IActionResult OnPost(string provider, string returnUrl = null)
{
// Request a redirect to the external login provider.
var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl });
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return new ChallengeResult(provider, properties);
}
The line above will always route to the last added Authentication ...
Mikael Håkansson (@wmmihaa) : we are currently working on higher priority very requested features (performance and resilience of the token cache adapters, and rotation of certificates)
This would be next.
Mikael Håkansson (@wmmihaa) Do you get it working with the new version?
I'm not successful. I already tried several combinations, still no luck.
Could you provide some demo code?
Ok, now I've found my mistake. The important thing is passing the value of null to the cookieScheme parameter and setting Cookie Authentication as default.
Mikael Håkansson (@wmmihaa) Is it working ? And how you differentiate that which user will be part of which tenant ?
How you modified this below code
public IActionResult OnPost(string provider, string returnUrl = null)
{
// Request a redirect to the external login provider.
var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl });
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return new ChallengeResult(provider, properties);
}
And how you differentiate that which user will be part of which tenant ?
There are a couple of ways you can do this. Default, you'd allow the user to select which identity provider to use. In my case,I persist each AAD configuration in the database together with the email domain and as the user types their email address I redirect based on the domain.
Activity
jmprieur commentedon Feb 17, 2021
Mikael Håkansson (@wmmihaa) : this is duplicate of #955
wmmihaa commentedon Feb 17, 2021
Not sure it is as this relates to multiple auth schemes of the same type
wmmihaa commentedon Feb 22, 2021
Is there a plan to support integration with multiple AAD using
AddMicrosoftIdentityWebAppAuthentication?jmprieur commentedon Feb 23, 2021
Mikael Håkansson (@wmmihaa) : AddMicrosoftIdentityWebAppAuthentication is a shortcut for the simple case where you don't want to specify the scheme, whereas the multi AAD scenario is the very case where you want to control the scheme.
You'll want to do;
We think we'll work on supporting this in 1.18.
wmmihaa commentedon Feb 23, 2021
I think the problem is in SignInManager.ConfigureExternalAuthenticationProperties which will always route to the same AAD independently of the provider...
The line above will always route to the last added Authentication ...
StartUp.cs:
Each of the line above work by it self, but not together
Let me know if you want med to demo this through a teams session
wmmihaa commentedon Feb 24, 2021
I've made short video to better explain the scenario and issue.
https://youtu.be/SSuciNOnt-0
hth
wmmihaa commentedon Feb 25, 2021
I've raised the issue in the aspnetcore repo: dotnet/aspnetcore#30472
wmmihaa commentedon Mar 3, 2021
Any news on this?
btw...I would not consider this an
enhancementbut abugdotnet/aspnetcore#30472 is closed so this is no longer
duplicate.jmprieur commentedon Mar 4, 2021
Mikael Håkansson (@wmmihaa) : we are currently working on higher priority very requested features (performance and resilience of the token cache adapters, and rotation of certificates)
This would be next.
wmmihaa commentedon Mar 4, 2021
Jean-Marc Prieur (@jmprieur) Thank you for the feedback. We will continue working on other things while we wait.
4 remaining items
jennyf19 commentedon May 24, 2021
Included in 1.11.0 release and documentation here.
wmmihaa commentedon May 24, 2021
Thank you jennyf19
sven5 commentedon Jul 8, 2021
Mikael Håkansson (@wmmihaa) Do you get it working with the new version?
I'm not successful. I already tried several combinations, still no luck.
Could you provide some demo code?
Thanks!
wmmihaa commentedon Jul 8, 2021
Hi Sven,
Yes it works for me. We're using v 1.14.0 (
Microsoft.Identity.Web&Microsoft.Identity.Web.UI):Startup.cs - ConfigureServices
appsettings.json
HTH
sven5 commentedon Jul 9, 2021
Ok my scenario is a little different. I'd like to use AAD and AAD B2C together in one web app.
My problem is that after logging in by using AAD the User is not authenticated in the app. Both authentication methods never work at the same time
sven5 commentedon Jul 9, 2021
Ok, now I've found my mistake. The important thing is passing the value of
nullto the cookieScheme parameter and setting Cookie Authentication as default.Faisal-developer commentedon Aug 13, 2022
Mikael Håkansson (@wmmihaa) Is it working ? And how you differentiate that which user will be part of which tenant ?
How you modified this below code
public IActionResult OnPost(string provider, string returnUrl = null)
{
// Request a redirect to the external login provider.
var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl });
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return new ChallengeResult(provider, properties);
}
wmmihaa commentedon Aug 15, 2022
Hi Faisal,
Yes I got it working.
There are a couple of ways you can do this. Default, you'd allow the user to select which identity provider to use. In my case,I persist each AAD configuration in the database together with the email domain and as the user types their email address I redirect based on the domain.
Your code looks good
Faisal-developer commentedon Aug 15, 2022
Mikael Håkansson (@wmmihaa) Got it. You are using this for mobile app ? I meaning azure ad is integrated with mobile app or using web app ?
wmmihaa commentedon Aug 15, 2022
It's a web application
Faisal-developer commentedon Aug 15, 2022
Mikael Håkansson (@wmmihaa) Do you have any idea how it will work for flutter mob app ?
wmmihaa commentedon Aug 15, 2022
Sorry, I have not worked with flutter.
rafaelcaviquioli commentedon Nov 29, 2022
I have the following configuration, AzureAdB2C is set as default, but when I open the application, I'm forwarded to AzureAdB2C signin page.
I would expect that when the user tries to open a not public page, it is forwarded to the auth provider configured in the default scheme.
I also have this policy configured: