-
Notifications
You must be signed in to change notification settings - Fork 218
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
Add multiple AAD authentication options using AddMicrosoftIdentityWebAppAuthentication not possible #971
Comments
Is there a plan to support integration with multiple AAD using |
@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. AddAuthentication(defaultScheme)
.AddMicrosoftIdentityWebApp(configSection1, scheme1)
AddAuthentication()
.AddMicrosoftIdentityWebApp(configSection2, scheme2) We think we'll work on supporting this in 1.18. |
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 |
I've made short video to better explain the scenario and issue. |
I've raised the issue in the aspnetcore repo: dotnet/aspnetcore#30472 |
Any news on this? dotnet/aspnetcore#30472 is closed so this is no longer |
@wmmihaa : we are currently working on higher priority very requested features (performance and resilience of the token cache adapters, and rotation of certificates) |
@jmprieur Thank you for the feedback. We will continue working on other things while we wait. |
@wmmihaa we have a preview package w/multiple auth scheme support. If you'd like to try it out, please send me an email: jeferrie@microsoft.com and I will send you the nuget package. we are still testing, so it's not on nuget yet. |
Included in 1.11.0 release and documentation here. |
Thank you @jennyf19 |
@wmmihaa Do you get it working with the new version? Thanks! |
Hi Sven, Startup.cs - ConfigureServicesforeach (var section in Configuration.GetSection("azureAd").GetChildren())
{
services.AddAuthentication()
.AddMicrosoftIdentityWebApp(section, section.Key, null);
} appsettings.json "azureAd": {
"AAD1": {
"Instance": "XXX",
"Domain": "XXX",
"TenantId": "XXX",
"ClientId": "XXX",
"CallbackPath": "/signin-oidc/aad1"
},
"AAD2": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "XXX",
"TenantId": "XXX",
"ClientId": "XXX",
"ClientSecret": "XXX",
"CallbackPath": "/signin-oidc/aad2"
}
} HTH |
Ok my scenario is a little different. I'd like to use AAD and AAD B2C together in one web app. services.AddAuthentication()
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"), Microsoft.Identity.Web.Constants.AzureAd, "cookiesAd");
services.AddAuthentication()
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAdB2C"), Microsoft.Identity.Web.Constants.AzureAdB2C, "cookiesB2C"); 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 |
Ok, now I've found my mistake. The important thing is passing the value of |
@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) |
Hi Faisal,
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 |
@wmmihaa Got it. You are using this for mobile app ? I meaning azure ad is integrated with mobile app or using web app ? |
It's a web application |
@wmmihaa Do you have any idea how it will work for flutter mob app ? |
Sorry, I have not worked with flutter. |
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. services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(options =>
{
configuration.Bind("AzureAdB2C", options);
options.Events ??= new OpenIdConnectEvents();
options.ResponseType = OpenIdConnectResponseType.Code;
options.Scope.Add(options.ClientId);
}, subscribeToOpenIdConnectMiddlewareDiagnosticsEvents: true, cookieScheme: null);
services.AddAuthentication()
.AddMicrosoftIdentityWebApp(options =>
{
configuration.Bind("AzureAdB2C", options);
// Replace with invitation custom policy and callback urls
configuration.Bind("AzureAdB2CInvitation", options);
options.ResponseType = OpenIdConnectResponseType.Code;
options.Scope.Add(options.ClientId);
options.Events ??= new OpenIdConnectEvents();
options.Events.OnRedirectToIdentityProvider += async (context) =>
{
var idTokenHint = context.Request.Query["id_token_hint"];
if (!string.IsNullOrEmpty(idTokenHint))
{
context.ProtocolMessage.IdTokenHint = idTokenHint;
}
await Task.CompletedTask.ConfigureAwait(false);
};
}, subscribeToOpenIdConnectMiddlewareDiagnosticsEvents: true, openIdConnectScheme: InvitationScheme, cookieScheme: null); I also have this policy configured: services
.AddMvcCore()
.AddApiExplorer()
.AddAuthorization(options =>
{
options.DefaultPolicy = new AuthorizationPolicyBuilder()
.AddAuthenticationSchemes(OpenIdConnectDefaults.AuthenticationScheme, AuthenticationExtensions.InvitationScheme)
.RequireAuthenticatedUser()
.Build();
options.AddPolicy(AuthenticationExtensions.SmAccessPolicy, policy =>
{
policy.AddAuthenticationSchemes(
OpenIdConnectDefaults.AuthenticationScheme,
AuthenticationExtensions.InvitationScheme
);
policy.RequireAssertion(context => context.User.HasClaim(c => c.Type == "extension_roles" && c.Value.Split(",").Contains("product.sm")));
});
}) |
Which version of Microsoft Identity Web are you using?
Microsoft Identity Web 1.6.0
Where is the issue?
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 differentCallbackPath
.Is there an other way to do this?
If I try to logging using
azuread1
it will say the user dows not exist in azuread2.onmicrosoft.com, while if I log in usingazuread2
I get an "Unable to unprotect the message.State" exception.The text was updated successfully, but these errors were encountered: