IdentityServer4和ASP.NET MVC之间的OpenID连接(.NET 4.6.2)

时间:2018-06-12 19:13:39

标签: c# asp.net-mvc identityserver4

我在.net核心上有一个IdentityServer4用于客户端,但是现在我想在asp.net mvc上使用一个客户端和.net framework 4.6.2

我为OWIN找到了这个解决方案https://github.com/IdentityServer/IdentityServer3.Samples/tree/master/source/Clients/MVC%20OWIN%20Client%20(Hybrid) 但是这段代码不起作用。

我为客户端配置了这个配置:

new Client
  {
    ClientId = "mvcClient",
    ClientName = "4.6.2 client",
    AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
    ClientSecrets =
       {
         new Secret("secretKey".Sha256())
       },
    RedirectUris = {"http://localhost:52244/signin-oidc"},
    PostLogoutRedirectUris = {"http://localhost:52244/signout-callback-oidc"},
    AllowedScopes = new List<string>
       {
         IdentityServerConstants.StandardScopes.OpenId,
         IdentityServerConstants.StandardScopes.Profile,
       },
    AllowOfflineAccess = true,
    RequireConsent = false,
    AlwaysIncludeUserClaimsInIdToken = true,
    AlwaysSendClientClaims = true
}

此配置在 .net 4.6.2 mvc客户端

    ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => true;
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
  AuthenticationType = "Cookies",
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
  ClientId = "AdminUiClient",
  ClientSecret = "AdminSpiritSecretKey",
  ResponseType = "code id_token",
  SignInAsAuthenticationType = "Cookies",
  Authority = "http://localhost:58506/", //IdentityServer4
  AuthenticationType = "oidc",
  RedirectUri = "http://localhost:52244/signin-oidc", //URL of Client website
  Scope = "offline_access",
  AuthenticationMode = AuthenticationMode.Active,
  RequireHttpsMetadata = false,
  UseTokenLifetime = false,
});

我的配置中出错了什么?

1 个答案:

答案 0 :(得分:0)

需要更多信息来确定这里的问题究竟是什么。乍一看,您放入客户端的ClientId和Secret与配置中的值不匹配。