我已经安装了IdentityServer4和客户端(混合Mvc客户端)。一切都好。以下流程起作用:
1.用户调用安全页面PageX(控制器受Authorize属性保护)
2.然后系统将流程重定向到IdentityServer上的“登录”页面
3.身份验证/授权后,IdentityServer将用户重定向到客户端配置(名为Home的页面)中定义的url(redirect_uri)。
现在,我不知道如何在第3步中实现重定向到请求原始页面的PageX。
我必须创建一个自定义AuthorizeAttribute来将SessionX的URL保存在会话存储中,而不是在回调页面中使用它?还是IdentityServer或客户端上有任何配置可以帮助我?
预先感谢
答案 0 :(得分:0)
这通常是您要使用state参数的目的。您的回调将保持原样返回状态值,然后您可以验证其中的URL是本地的并自动重定向到它。
我建议使用.net中的DataProtection功能保护该值免遭篡改。
答案 1 :(得分:0)
成功登录后,默认情况下,IdentityServer中间件尝试重定向到同意页面,在该页面中向用户通知“允许范围”。在此页面中显示了客户mvc站点将有权访问的声明:用户标识符,用户配置文件,电子邮件等。 如果未设置,则在定义MVC客户端时可以设置:“ RequireConsent = false”。在这种情况下,IdentityServer将重定向回“ RedirectUris”,而不会显示同意页面。
示例:
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "mvc",
ClientName = "mvc Client",
ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
RedirectUris = { "http://localhost:5002/signin-oidc" },
PostLogoutRedirectUris = { "http://localhost:5002/signout-callback-oidc" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email
},
RequireConsent = false
}
};
}
我在IdentityServer4演示和快速入门中注意到的另一件事是,您需要以下NuGet软件包: 对于客户网站: IdentityModel, Microsoft.AspNetCore.All
对于IdentityServer身份验证应用程序: IdentityServer4, IdentityServer4.AccessTokenValidation, IdentityServer4.AspNetIdentity, Microsoft.AspNetCore.All
您可以安装这些软件包只是为了使演示正常工作。