我有2个Auth0帐户,当客户端从任何一个帐户登录时,它们都会生成jwt令牌。我已经知道如何在1个域的Web API中对令牌进行身份验证,并且它工作正常。我想知道如何对2个Auth0域进行身份验证。现在,它正在对tldev111.auth0.com域上的所有用户进行身份验证,我也想对tldev123.auth0.com域上的用户进行身份验证
Startup.cs-
public void Configuration(IAppBuilder app)
{
var domain = $"https://{ConfigurationManager.AppSettings["Auth0Domain"]}/";
var apiIdentifier = ConfigurationManager.AppSettings["Auth0ApiIdentifier"];
var keyResolver = new OpenIdConnectSigningKeyResolver(domain);
app.UseJwtBearerAuthentication(
new JwtBearerAuthenticationOptions
{
AuthenticationMode = AuthenticationMode.Active,
TokenValidationParameters = new TokenValidationParameters()
{
ValidAudience = apiIdentifier,
ValidIssuer = domain,
IssuerSigningKeyResolver = (token, securityToken, kid, parameters) => keyResolver.GetSigningKey(kid)
}
});
// Configure Web API
WebApiConfig.Configure(app);
}
WebApiConfig-
public static void Configure(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
app.UseWebApi(config);
}
web.config应用程序设置-
<appSettings>
<add key="Auth0Domain" value="tldev111.auth0.com" />
<add key="Auth0ApiIdentifier" value="https://aaa/SRTAPI/api" />