我有一个 ASP.NET MVC站点,IdentityServer4主机和一个Web API。
当我使用外部提供商(Facebook)登录MVC站点时,我登录正常。从MVC站点,我还可以正确使用Web API。
但是,第二天,我仍然登录到MVC站点,但是当我尝试访问Web API时,我得到一个“未经授权的例外”。
因此,尽管我仍然登录到 MVC 站点,但我不再通过身份验证从 MVC 站点中调用 Web API。
我想知道如何处理这种情况,以及如何配置IdentityServer4。
为什么一天后我仍然登录到 MVC 站点?如何配置?
如果我仍然登录到 MVC 站点,为什么我仍然无法调用 Web API?
我可以同步过期时间吗?或者我应该如何处理这个问题?
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 id_token"; // Use hybrid flow
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("mgpApi");
options.Scope.Add("offline_access");
});
所以它使用混合流。
在 IdentityServer 中,MVC 客户端的配置如下:
new Client
{
EnableLocalLogin = false,
ClientId = "mgpPortal",
ClientName = "MGP Portal Site",
AllowedGrantTypes = GrantTypes.Hybrid,
// where to redirect to after login
RedirectUris = mgpPortalSite.RedirectUris,
// where to redirect to after logout
PostLogoutRedirectUris = mgpPortalSite.PostLogoutRedirectUris,
// secret for authentication
ClientSecrets = mgpPortalSite.ClientSecrets.Select(cs => new Secret(cs.Sha256())).ToList(),
倚天杖
相关分类