2017-12-05 14 views
2

今日私はidentityserver4のデモを使用して検証サーバーを構築し、私はasp.netコアクライアントとクライアントopenidログインを使用することができます。asp.net mvcログインinvalid_requestエラー

が、私はOpenIDをして私のasp.net mvc5クライアントにログインできなかった、プロンプトのエラーがある:INVALID_REQUEST、ここ

は(getclientと私のidentityserver4の設定コードである)

// clients want to access resources (aka scopes) 
    public static IEnumerable<Client> GetClients() 
    { 
     // client credentials client 
     return new List<Client> 
     { 
      // OpenID Connect hybrid flow and client credentials client (MVC) 
      new Client 
      { 
       ClientId = "mvc", 
       ClientName = "MVC Client", 
       AllowedGrantTypes = GrantTypes.HybridAndClientCredentials, 

       RequireConsent = true, 

       ClientSecrets = 
       { 
        new Secret("secret".Sha256()) 
       }, 

       RedirectUris = { "http://localhost:5002/signin-oidc" }, 
       PostLogoutRedirectUris = { "http://localhost:5002/signout-callback-oidc" }, 

       AllowedScopes = 
       { 
        IdentityServerConstants.StandardScopes.OpenId, 
        IdentityServerConstants.StandardScopes.Profile, 
        "api1" 
       }, 
       AllowOfflineAccess = true 
      } 
     }; 
    } 
} 

と私のクライアントは、ClientSecret = GetSHA256HashFromString( "secret")を設定し、私はprvateを作成します。文字列をsha256に変換するGetSHA256HashFromString()メソッド。ここ

は私のコードは次のとおりです。5000を、それは私にエラーを与えている:

public void ConfigureAuth(IAppBuilder app) 
    { 
     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = "Cookies" 
     }); 

     app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
     { 
      AuthenticationType = "oidc", 
      SignInAsAuthenticationType = "Cookies", 
      Authority = "http://localhost:5000", //ID Server SSO Server 
      ClientId = "mvc", 
      ClientSecret = GetSHA256HashFromString("secret"), 
      ResponseType = "code id_token", 
      RedirectUri = "http://localhost:5002/signin-oidc", //URL of Client website 
      PostLogoutRedirectUri = "http://localhost:5002/signout-callback-oidc", //URL of Client website 
      Scope = "api1", 
      AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active, 



      RequireHttpsMetadata = false, 

     }); 

と私はMVCクライアントを実行するF5キーを押して、ログインのボタンを押すと、ブラウワーは、ローカルホストにジャンプすることができます:

Sorry, there was an error : invalid_request and the other error info are : Request Id: 0HL9RHBTJIT3T:00000003**

ありがとうございます。

+0

私はあなたの問題はGetSHA256HashFromString( "secret")を使っていると思っています。ハッシュしないで "secret"を送信するだけで、サーバはクリアテキストの秘密を送ると予想します。アイデンティティ・サーバーは送信したものをハッシュし、データベース内のものと比較します。 – DaImTo

答えて

1

ClientSecretの値は、ハッシュされていないであるの実際の秘密値である必要があります。

永続的なデータストレージを使用すると、秘密はハッシュとして保存され、攻撃者がストレージが侵害された場合に備えてクライアントの秘密を入手できなくなります。

あなたの場合、秘密の値は「秘密」です。したがって、コードは になります。ClientSecret = "secret"

関連する問題