2016-11-08 8 views
3

私はIDCによって管理されている権限を持つMVCアプリケーションを持っています。初めてWebにアクセスすると、それはidentityserverのlogginページにリダイレクトされ、その後私は再び自分のWebにリダイレクトされます。thinktectureの自動ログインを無効にする方法IdentityServer

私の問題は、アイデンティティサーバのログアウト時に、アイデンティティサーバにリダイレクトされましたが、アイデンティティサーバにリダイレクトされていますが、ログインが自動的に行われます。

私はそれがクライアントでクッキーがまだ生きているからです(私はブラウザで手動ですべてのクッキーを削除し、ユーザー/パスが必要な場合)。

自動ログインを無効にするにはどうすればいいですか(そのユーザー/パスは常に必要です)。

私のスタートアップクライアント構成は次のようである:事前に

app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      LoginPath = new PathString("/Home/Logged/"), 
      AuthenticationType = "Cookies", 
      ExpireTimeSpan = TimeSpan.FromDays(2), 
      SlidingExpiration = true, 
      CookieName = ".AspNet.MyApp" 

     }); 


     app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
     { 
      ClientId = "MyApp", 
      Authority = IS_URL, 
      RedirectUri = localHostURL + "/Home/Logged/", 
      PostLogoutRedirectUri = localHostURL + "/Account/Login/", 
      ResponseType = "code id_token token", 
      Scope = "openid profile read write sampleApi", 
      SignInAsAuthenticationType = "Cookies", 

      UseTokenLifetime = true, 

      Notifications = new OpenIdConnectAuthenticationNotifications 
      { 
       SecurityTokenValidated = async n => 
       { 
        var nid = new ClaimsIdentity(
         n.AuthenticationTicket.Identity.AuthenticationType, 
         "given_name", 
         "role"); 

        // get userinfo data 
        var userInfoClient = new UserInfoClient(
         new System.Uri(n.Options.Authority + "/connect/userinfo"), 
         n.ProtocolMessage.AccessToken); 

        var userInfo = await userInfoClient.GetAsync(); 
        userInfo.Claims.ToList().ForEach(ui => nid.AddClaim(new Claim(ui.Item1, ui.Item2))); 

        //keep the id_token for logout 

        nid.AddClaim(new Claim("id_token", n.ProtocolMessage.IdToken)); 

        // add access token for sample API 
        nid.AddClaim(new Claim("access_token", n.ProtocolMessage.AccessToken)); 

        // keep track of access token expiration 
        nid.AddClaim(new Claim("expires_at", TimeSpan.FromDays(2).ToString())); 

        // add some other app specific claim 
        nid.AddClaim(new Claim("app_specific", "some data")); 

        n.AuthenticationTicket = new AuthenticationTicket(
         nid, 
         n.AuthenticationTicket.Properties); 
       }, 
       RedirectToIdentityProvider = n => 
       { 
        if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest) 
        { 
         var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token"); 

         if (idTokenHint != null) 
         { 
          n.ProtocolMessage.IdTokenHint = idTokenHint.Value; 
         } 
        } 

        return Task.FromResult(0); 
       } 
      } 
     }); 

ありがとう!

答えて

0

ログインリクエスト/ idsrvへのリダイレクトの場合、promptパラメータをloginに設定します。

OnRedirectToIdentityProvider = n => 
{ 

    if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.Authentication) 
    {  
     n.ProtocolMessage.Prompt = "login"; 
    } 

    return Task.FromResult(0); 
} 

IdSrv docs(プロンプトを参照)

prompt (optional)

loginログインUIは、ユーザーが既に署名して有効なセッションを持っている場合であっても、表示されます。

OpenId Connect spec around /authorize requests

prompt=login

認証サーバは再認証のためのエンドユーザーを要求すべきです。エンドユーザーを再認証できない場合は、通常はlogin_requiredというエラーを返します。

1

identityserverからログアウトするには、エンドセッションエンドポイントにリダイレクトする必要があります。

通常、/connect/endsessionです。このようにして、認証セッションCookieをクリアすることができます。私は同様の要件を持っていた https://openid.net/specs/openid-connect-session-1_0.html#RPLogout

0

は、仕様を参照してください。最もエレガントな方法ではありませんが、私はクッキーの有効期限を10秒に減らして、スライディングエクスプレッションをオフにして解決しました。 ここでは、信頼関係者が10秒以内に戻ると、ログインプロンプトがバイパスされます。

関連する問題