我有以下场景:4.8 上的普通 .NET Web API 用作身份 API,以及需要具有承载令牌才能成为身份 API 的 .NET 5.0 Web API(4.8 .net 之一)。
我正在纠结要在 .NET Core API 中使用什么配置。
// Normal .net API on 4.8 net work as Identity API configurations
public void ConfigureAuth(IAppBuilder app)
{
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId, null, null),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = 15
)),
AllowInsecureHttp = false,
RefreshTokenProvider = new ApplicationRefreshTokenProvider(),
};
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
}
// .NET 5.0 API that need to have bearer token to be identity API (.net 4.8 from above)
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer("oauth", o =>
{
o.Authority = "http://localhost:1000/Token";
//o.Audience = "test";
});
}
我认为 .AddJwtBearer(...)
的方向是错误的,因为 Identity API 生成的令牌是“普通”承载令牌,而不是 JWT。
我将非常感谢任何帮助以在 .NET Core API 中实现正确的配置