I was trying to implement Multitenant Authentication (Which I'm learning) and so far I've succeeded in implementing authentication my application in Single tenant.
The code which I've used for single tenant is
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = ConfigurationManager.AppSettings["AuthclientId"],
Authority = "https://login.microsoftonline.com/abc.onmicrosoft.com/",
});
}
Here; first I register my application in ABC AAD and get the client ID then put it my configuration. All works fine.
But now I've to implement this with multitenant type. Even though it's multitenant, I've to allow only 2 tenant users only. Let's say abc.onmicrosoft.com and contoso.onmicrosoft.com
So far I've done like registering my application in ABC tenant and Contoso tenant then get 2 client Id's. But my issue there is no way to provide 2 client ID's in the UseOpenIdConnectAuthentication (see my updated code below)
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = ??,
Authority = "https://login.microsoftonline.com/common/",
TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = false
},
});
}
P.S This is new to me. I may be wrong, please correct me in order to get things in the right path
Update 1:
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
//ClientId = authClientID1,//App ID registered with 1st Tenant
Authority = "https://login.microsoftonline.com/common/",
RedirectUri= "https://localhost:44376/",
TokenValidationParameters = new TokenValidationParameters
{
ValidAudiences = new List<string>{ authClientID1, authClientID2 },
ValidateIssuer =true,
ValidIssuers= new[] { "https://sts.windows.net/<tenantID1>/", "https://sts.windows.net/<tenantID2>/" }
},
});
After commenting the ClientID I'm receiving the error like AADSTS900144: The request body must contain the following parameter: 'client_id'
I'm not sure how to give my two ClientID and tenant ID in order to authenticate users only from my two tenants!