2016-07-05 8 views
4

主な問題は、identityServer4からログアウトする適切な方法が見つからないことです。OpenIDConnect AspNetCore ID_tokenを使用したログアウト

詳細説明:

new Client 
      { 
       ClientId = "testsoft", 
       ClientName = "testsoft", 
       ClientSecrets = new List<Secret> 
       { 
        new Secret("secret".Sha256()) 
       }, 
       ClientUri = "http://localhost:55383/",//clientside web application url 
       AllowedGrantTypes = GrantTypes.Hybrid, 
       AllowAccessTokensViaBrowser = true, 
       RedirectUris = new List<string> 
       { 
        "http://localhost:55383/signin-oidc" 
       }, 
       RequireConsent = false, 
       AllowedScopes = new List<string> 
       { 
        StandardScopes.OpenId.Name, 
        StandardScopes.Profile.Name, 
        StandardScopes.Email.Name, 
        StandardScopes.Roles.Name, 
        StandardScopes.OfflineAccess.Name, 

        "api1", "api2", 
       }, 
      }, 

の下に私がログインすることができたとして

クライアント側のWebアプリケーションstartup.csローカルで実行されている次のコード

app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationScheme = "Cookies", 
      AutomaticAuthenticate = true 
     }); 
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions 
     { 
      AuthenticationScheme = "oidc", 
      SignInScheme = "Cookies", 
      Authority = "http://localhost:1941/",//local identityServer4 
      ClientId = "testsoft", 
      ClientSecret = "secret", 
      ResponseType = "code id_token token", 
      GetClaimsFromUserInfoEndpoint = true, 
      RequireHttpsMetadata = false, 
      Scope = { "openid", "profile", "email" }, 
      TokenValidationParameters = new TokenValidationParameters() 
      { 
       NameClaimType = "name", 
       RoleClaimType = "role" 
      }, 
      AutomaticAuthenticate = false, 
      AutomaticChallenge = true 
    }); 

IdentityServer4が含まれていますが、クライアントが追加されましたこのようにMVCのController-Viewにクレームを表示する

[Authorize] 
    public IActionResult About() 
    { 
     return View((User as ClaimsPrincipal).Claims); 
    } 

表示されるビューは次のようなものです。

public async Task<IActionResult> LogOut() 
    { 

     await HttpContext.Authentication.SignOutAsync("Cookies"); 
     return Redirect("~/"); 
    } 

下記しかし、問題は、私はIdentityServerからログアウトする方法を見つけることができないであるとそこにはid_token

And the view displayed was like this. Note that there is no id_token

ではありませんそして、私はクッキーを使用してログアウトすることができたことに注意してください。私が近づくほど、使用することでした /connect/endsession?id_token_hint=...&post_logout_redirect_uri=https://myapp.com

しかし、私はコードで生のid_tokenを取得する方法を見つけることができませんでした。上記のAbout()メソッドでは、私は主張(id_tokenの解読された内容だと思います)だけを取得しています。これらの主張リストには、id_tokenは見えません。しかし、何とかこのURLにあるid_tokenをこのURLで入手することができました。http://localhost:55383/signin-oidcそして、(上記のURLの助けを借りて)identityServerのログアウトがトリガーされました。

私は、次のような質問があります。

  1. コードでid_tokenを取得する方法を? (手作業によるコピーの代わりに)
  2. ログアウトするより良い方法はありますか?またはログアウトするAspnetCore/Oidcフレームワークメソッドがあります(適切なパラメータを持つ正しいサーバーAPIを呼び出します)。
  3. ログアウトして何度もログインできましたが、id_tokenは同じように見えました。例:Bobユーザー、Aliceユーザーの両方が同じid_tokenを持っていました。 Cookieがクリアされ、id_tokenが同じでも、別のユーザーがビューに表示されるたびにid_tokenはログイン/ユーザーごとに異なるはずはありませんか?
  4. 私はid_tokenとしてランダムな文字列を与えても、SignoutのURLが機能しました。これは、IdentityServer4のログアウト機能がid_tokenに基づいて機能しないことを意味しますか?ログアウトするための
+1

あなたの質問に答えられましたか?私は同じ問題に直面している。 –

答えて

0

、あなたのクライアントのログアウトアクションで

HttpContext.Authentication.SignOutAsync("oidc"); 

をtry-たのですか?

+0

実際、これは正しい答えです。ログインしているすべてのコンテキストをログアウトする必要があります。あなたのクライアント設定のサインインリダイレクトuriのほかに、サインアウトリダイレクトuriを指定することもできます。詳細は、IdentityServer4のドキュメントを参照してください。 – Flawless

関連する問題