When you configure identtyserver with external provider, In AuthenticationOptions you typically set AutheticationType to some string. Like below
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
{
AuthenticationType = "Google",
Caption = "Sign-in with Google",
SignInAsAuthenticationType = signInAsType,
ClientId = ConfigurationManager.AppSettings["google:clientid"],
ClientSecret = ConfigurationManager.AppSettings["google:clientsecret"],
});
Then in client application you can set the acrvalues to Authentication-type like below
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Notifications = new OpenIdConnectAuthenticationNotifications
{
RedirectToIdentityProvider = (n) =>
{
if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.AuthenticationRequest)
{
if(n.Request.Uri == "someurl")
{
//set acrvalues. the value of the `idp`, (which is `Google` in this case) must match with the `AutheticationType` you set in IdentityServer
n.ProtocolMessage.AcrValues = "idp:Google";
}
}
return Task.FromResult(0);
}
}
Also note that the idp value is case sensitive.
The other option (which i have NOT tried). Instead of setting idp you set the tenant in client application.
n.ProtocolMessage.AcrValues = "tenant:" + n.Request.Uri.ToString();
And as @TheRock mentioned, In IndentityServer check the tenant in SignInMessage and override Idp
public override Task PreAuthenticateAsync(PreAuthenticationContext context)
{
if(context.SignInMessage.Tenant = "sometenant")
{
context.SignInMessage.IdP = "Google";
return base.PreAuthenticateAsync(context);
}
}
In this way as you keep adding new external providers, you don't have to change code in client application. You only to update IndentityServer code. This especially help if you have multiple client applications connecting to same identity server.