Add multiple AAD authentication options using AddMicrosoftIdentityWebAppAuthentication not possible
See original GitHub issueWhich 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
.
Is there an other way to do this?
"azuread1": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "azuread1.onmicrosoft.com",
"TenantId": "xxxxx",
"ClientId": "xxxxxx",
"ClientSecret": "xxxxx",
"CallbackPath": "/signin-oidc/azuread1",
"SignedOutCallbackPath": "/signout-callback-oidc"
},
"azuread2": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "azuread2.onmicrosoft.com",
"TenantId": "yyyyy",
"ClientId": "yyyyy",
"ClientSecret": "yyyyy",
"CallbackPath": "/signin-oidc/azuread2",
"SignedOutCallbackPath": "/signout-callback-oidc"
},
services.AddMicrosoftIdentityWebAppAuthentication(configuration: Configuration,
configSectionName: "azuread1",
openIdConnectScheme: "azuread1",
cookieScheme: null);
services.AddMicrosoftIdentityWebAppAuthentication(configuration: Configuration,
configSectionName: "azuread2",
openIdConnectScheme: "azuread2",
cookieScheme: null);
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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:24
Top Results From Across the Web
Multiple authentication schemes: Azure AD and ...
I need to use two authentication schemes in my app: 1.) Azure AD B2C user login. 2.) Azure AD machine-to-machine daemon login.
Read more >Enable web app authentication options using Azure Active ...
This article discusses several ways to enable web app authentication options.
Read more >.net 6.0 - How can I authenticate a user with Azure AD ...
The key is to add multiple authentication schemes, one for each azure AD client. Once these schemes are added, they each then need...
Read more >How to Use the Azure Active Directory Authentication for MVC ...
This guide demonstrates how to integrate AzureAD to an ABP application that enables users to sign in using OAuth 2.0 with credentials from...
Read more >Authenticate an ASP.NET Core Web App With Microsoft ...
So you want to authenticate your ASP.NET Core web app with Azure AD. It sounds daunting, but with a little help from the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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