我有一个 ASP.NET MVC 站点、IdentityServer4 主机和一个 Web API。
当我使用外部提供程序 (Facebook) 登录 MVC 站点时,我可以正常登录。从 MVC 站点,我还可以正确使用 Web API。
但是,第二天,我仍然登录到 MVC 站点,但是当我尝试访问 Web API 时,我收到“未授权异常”。
因此,尽管我仍然登录到 MVC 站点,但我不再通过身份验证从 MVC 站点内调用 Web API。
我想知道如何处理这种情况,以及应如何配置 IdentityServer4。
MVC 应用程序配置如下:
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = "Cookies";
options.Authority = mgpIdSvrSettings.Authority;
options.RequireHttpsMetadata = false;
options.ClientId = mgpIdSvrSettings.ClientId;
options.ClientSecret = mgpIdSvrSettings.ClientSecret; // Should match the secret at IdentityServer
options.ResponseType = "code …Run Code Online (Sandbox Code Playgroud)