我正在创建自动生成的文档功能作为MVC的WEB-API应用程序。作为API控制器的一般终点,最初的API端点可以与令牌认证一起使用。但是在我尝试使用cookie模式进行身份验证的MVC控制器后,它按预期工作但API控制器失败"授权被拒绝"。
在Startup.cs
中public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
var auth = ConfigurationManager.AppSettings["AuthAuthority"];
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<String, String>();
var tokenOptions = new IdentityServerBearerTokenAuthenticationOptions();
tokenOptions.Authority = auth;
tokenOptions.PreserveAccessToken = true;
//adding for Outh2 authentication
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = "https://localhost:44300/",
ClientId = "mvc_Doc",
RedirectUri = "http://localhost:64741/Help",
ResponseType = "id_token token",
SignInAsAuthenticationType = "Cookies",
UseTokenLifetime = false,
Scope = "openid profile",
});
app.UseIdentityServerBearerTokenAuthentication(tokenOptions);
app.UseStageMarker(PipelineStage.Authenticate);
我该如何处理?