den*_*li8 5 asp.net-mvc-4 asp.net-core identityserver4
今天我使用identityserver4的demo搭建了一个验证服务器,并且可以使用asp.net core客户端通过openid登录客户端。
\n\n但是我无法使用openid登录我的asp.net mvc5客户端,提示的错误是\xef\xbc\x9a invalid_request,
\n\n这是我的 Identityserver4 配置代码与 getclient()
\n\n// clients want to access resources (aka scopes)\n public static IEnumerable<Client> GetClients()\n {\n // client credentials client\n return new List<Client>\n {\n // OpenID Connect hybrid flow and client credentials client (MVC)\n new Client\n {\n ClientId = "mvc",\n ClientName = "MVC Client",\n AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,\n\n RequireConsent = true,\n\n ClientSecrets = \n {\n new Secret("secret".Sha256())\n },\n\n RedirectUris = { "http://localhost:5002/signin-oidc" },\n PostLogoutRedirectUris = { "http://localhost:5002/signout-callback-oidc" },\n\n AllowedScopes =\n {\n IdentityServerConstants.StandardScopes.OpenId,\n IdentityServerConstants.StandardScopes.Profile,\n "api1"\n },\n AllowOfflineAccess = true\n }\n };\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n下面的代码是我的asp.net mvc5 clentConfigureAuth(),因为idenetiyServer4定义ClientSecrets是“secret”。Sha256(),所以在这个mvc客户端中,我设置ClientSecret = GetSHA256HashFromString(“secret”),我创建私有方法 GetSHA256HashFromString() 将字符串转换为 sha256。
\n\n这是我的代码:
\n\npublic void ConfigureAuth(IAppBuilder app)\n {\n app.UseCookieAuthentication(new CookieAuthenticationOptions\n {\n AuthenticationType = "Cookies"\n });\n\n app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions\n {\n AuthenticationType = "oidc",\n SignInAsAuthenticationType = "Cookies",\n Authority = "http://localhost:5000", //ID Server SSO Server\n ClientId = "mvc",\n ClientSecret = GetSHA256HashFromString("secret"),\n ResponseType = "code id_token",\n RedirectUri = "http://localhost:5002/signin-oidc", //URL of Client website\n PostLogoutRedirectUri = "http://localhost:5002/signout-callback-oidc", //URL of Client website\n Scope = "api1",\n AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,\n\n\n\n RequireHttpsMetadata = false,\n\n });\nRun Code Online (Sandbox Code Playgroud)\n\n我按f5运行mvc客户端,然后按登录按钮,浏览器可以跳转到localhost:5000,但它给我一个错误:
\n\n\n\n\n抱歉,出现错误:invalid_request,其他错误信息为:\n 请求 ID:0HL9RHBTJIT3T:00000003**
\n
多谢。
\nClientSecret 的值应该是实际的秘密值而不是散列值。
当您使用持久数据存储时,秘密将以哈希形式存储,以防止攻击者在您的存储受到损害时获取您客户端的秘密。
在你的情况下,秘密值是“秘密”。所以代码将是 ClientSecret = "secret"
| 归档时间: |
|
| 查看次数: |
6309 次 |
| 最近记录: |