2016-08-30 1 views
0

Wir haben Problem mit dem folgenden CodeIdentity Server 3 Nach der Anmeldung Looping Ausgabe

public void Configuration(IAppBuilder app) 
 
     { 
 
      AntiForgeryConfig.UniqueClaimTypeIdentifier = IdentityServer3.Core.Constants.ClaimTypes.Subject; 
 
      JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>(); 
 
      app.Map("/identity", idsrvApp => 
 
      { 
 
       idsrvApp.UseIdentityServer(new IdentityServerOptions 
 
       { 
 
        SiteName = "Authentication Server", 
 
        SigningCertificate = LoadCertificate(), 
 
        IssuerUri = "https://localhost:44305/", 
 
        Factory = new IdentityServerServiceFactory() 
 
           .UseInMemoryUsers(Users.Get()) 
 
           .UseInMemoryClients(Clients.Get()) 
 
           .UseInMemoryScopes(Scopes.Get()), 
 
        //EnableWelcomePage = false, 
 
        RequireSsl = true, 
 
        AuthenticationOptions = new IdentityServer3.Core.Configuration.AuthenticationOptions 
 
        { 
 
         EnablePostSignOutAutoRedirect = true, 
 
         IdentityProviders = ConfigureIdentityProviders 
 
        }, 
 
       }); 
 
      }); 
 

 
      app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
 
      { 
 
       Authority = "https://localhost:44305/identity", 
 
       RedirectUri = "https://localhost:44305/", 
 
       ClientId = "mvc", 
 
       Scope = "openid", 
 
       ResponseType = "id_token token", 
 
       SignInAsAuthenticationType = "Cookies", 
 
       UseTokenLifetime = false, 
 
       Notifications = new OpenIdConnectAuthenticationNotifications 
 
       { 
 
        SecurityTokenValidated = async n => 
 
        { 
 
         var nid = new ClaimsIdentity(
 
          n.AuthenticationTicket.Identity.AuthenticationType, 
 
          IdentityServer3.Core.Constants.ClaimTypes.GivenName, 
 
          IdentityServer3.Core.Constants.ClaimTypes.Role); 
 

 
         // get userinfo data 
 
         var userInfoClient = new UserInfoClient(
 
          new 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", DateTimeOffset.Now.AddSeconds(int.Parse(n.ProtocolMessage.ExpiresIn)).ToString())); 
 

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

 
         n.AuthenticationTicket = new AuthenticationTicket(
 
          nid, 
 
          n.AuthenticationTicket.Properties); 
 
         var data = ClaimsPrincipal.Current.Identity; 
 
         
 
        }, 
 

 
        RedirectToIdentityProvider = n => 
 
        { 
 
         if (n.ProtocolMessage.RequestType == Microsoft.IdentityModel.Protocols.OpenIdConnectRequestType.LogoutRequest) 
 
         { 
 
          var idTokenHint = n.OwinContext.Authentication.User.FindFirst("id_token"); 
 

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

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

 
      app.UseCookieAuthentication(new CookieAuthenticationOptions 
 
      { 
 
       AuthenticationType = "Cookies", 
 
          }); 
 

 
      
 
     } 
 

 
     public static X509Certificate2 LoadCertificate() 
 
     { 
 
      return new X509Certificate2(
 
       string.Format(@"{0}\bin\identityServer\idsrv3test.pfx", AppDomain.CurrentDomain.BaseDirectory), "idsrv3test"); 
 
     }

Ausgabe wie ist beim Anschließen an Looping, dass die Zeit Identität geht successed.

Antwort

1

Wie versuchen Sie, auf die Website zuzugreifen? Ich denke, Sie greifen über HTTP darauf zu. Das Ergebnis ist ein Cookie-Problem, das für HTTPS und nicht für HTTP gesetzt ist und weiterhin versucht, sich an sich selbst weiterzuleiten.

ich das hier mit einer Antwort in der Tiefe erklärt: OWIN and Azure AD HTTPS to HTTP Redirect Loop

+0

I Asp.net WebFroms und Identity Server 3.Webconfig Berechtigung gesetzt bin mit und seine direkt für Identity Server-Login-Seite und nach dem Login successed seinem nicht. –

+0

Die Technologie ist nicht wirklich relevant. Es sollte mit jedem von ihnen funktionieren. Sehen Sie sich die verknüpfte Antwort an. – ranieuwe

+0

Gleiche Struktur funktioniert in MVC side.its funktioniert gut in MVC –

Verwandte Themen