我有一个使用openiddict的Asp.Net核心项目设置。我使用的一个包(Asp.Net Odata)不支持端点路由,所以我在ConfigureServices中禁用了它
services.AddControllers(c=>c.EnableEndpointRouting = false)
问题是,当我这样做时,openiddict扩展方法GetOpenIddictServerRequest返回null。只要启用了端点路由,一切都可以正常工作
[HttpPost("~/oauth/token"), Produces("application/json")]
public async Task<IActionResult> Token()
{
var request = HttpContext.GetOpenIddictServerRequest();
...我注册openiddict,如下所示
services.AddOpenIddict()
.AddCore(options =>
{
// Configure OpenIddict to use the Entity Framework Core stores and entities.
options.UseEntityFrameworkCore()
.UseDbContext<MiPayOnlineCoreContext>();
})
.AddServer(options =>
{
options.SetAccessTokenLifetime(TimeSpan.FromMinutes(5));
options.SetRefreshTokenLifetime(TimeSpan.FromMinutes(11));
options.SetTokenEndpointUris("/oauth/token");
options.AllowPasswordFlow();
options.AllowRefreshTokenFlow();
options.SetIssuer(new Uri(authSettings[nameof(JWTSettings.Issuer)]));
options.AddSigningCertificate(certificate);
options.AddEncryptionCertificate(certificate);
// Mark the "email", "profile" and "roles" scopes as supported scopes.
options.RegisterScopes(OpenIddictConstants.Scopes.Email,
OpenIddictConstants.Scopes.Profile,
OpenIddictConstants.Scopes.Roles);
options.UseAspNetCore()
.EnableStatusCodePagesIntegration()
.EnableAuthorizationEndpointPassthrough()
.EnableLogoutEndpointPassthrough()
.EnableTokenEndpointPassthrough()
.EnableUserinfoEndpointPassthrough();
});是否可以在禁用端点路由的情况下使其工作?
发布于 2019-12-16 23:12:38
这是代码中的一个错误:您没有将app.UseMvc()放在正确的位置。
确保它出现在app.UseAuthentication()和app.UseAuthorization()之后,错误就会消失。
https://stackoverflow.com/questions/59256720
复制相似问题