2017-09-04 15 views
2

나는 IdentityServer3로 보안을 설정하려고하는 매우 간단한 MVC5 웹 사이트를 가지고 있습니다.왜 IdentityServer가 https가 아닌 http로 리디렉션됩니까?

내 웹 사이트와 내 IdentityServer 인스턴스는 모두 AppHarbor의 별도 사이트로 호스팅됩니다. 두 가지 모두 https 뒤에 있습니다.

[Authorize] 속성 (예 : /Home/About)으로 보호되는 웹 사이트의 리소스를 클릭하면 성공적으로 IdentityServer로 리디렉션되고 성공적으로 인증 할 수 있습니다.

IdentityServer가 웹 사이트에 대한 응답을 app.FormPostResponse.js을 통해 다시 게시하면 웹 사이트는 요청 된 자원에 대한 302 리디렉션으로 응답합니다. 그러나 이 리디렉션은 https가 아닌 http입니다 (네트워크 추적은 참조).

이건 내 IdentityServer 구성에 문제가있는 것 같지만 잘못된 점에 대해서는 알려 주시면 감사하겠습니다.

(AppHarbor가 SSL 종료 IIS, 앞에 리버스 프록시 (내가 믿는 nginx를) 사용 -. 그래서 나는 IdentityServer 문서에 따라,이 시나리오 RequireSsl = false을)를 여기에

내 웹 사이트의 Startup.cs

입니다 여기
public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = "Cookies" 
     }); 

     app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
     { 
      Authority = "https://<my-idsrv3>.apphb.com/identity", 

      ClientId = "<my-client-id>", 
      Scope = "openid profile roles email", 
      RedirectUri = "https://<my-website>.apphb.com", 
      ResponseType = "id_token", 

      SignInAsAuthenticationType = "Cookies", 

      UseTokenLifetime = false 
     }); 

     JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>(); 
    } 
} 

내 IdentityServer3 인스턴스에서 Startup.cs입니다 : 여기

public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     app.Map("/identity", idsrvApp => 
     { 
      idsrvApp.UseIdentityServer(new IdentityServerOptions 
      { 
       SiteName = "My Identity Server", 
       SigningCertificate = Certificates.LoadSigningCertificate(), 
       RequireSsl = false, 
       PublicOrigin = "https://<my-idsrv3>.apphb.com", 

       Factory = new IdentityServerServiceFactory() 
        .UseInMemoryUsers(Users.Get()) 
        .UseInMemoryClients(Clients.Get()) 
        .UseInMemoryScopes(Scopes.Get()) 
      }); 
     }); 
    } 
} 

내 웹 사이트의 정의입니다 클라이언트 : 여기

new Client 
{ 
    Enabled = true, 
    ClientName = "My Website Client", 
    ClientId = "<my-client-id>", 
    Flow = Flows.Implicit, 

    RedirectUris = new List<string> 
    { 
     "https://<my-website>.apphb.com" 
    }, 

    AllowAccessToAllScopes = true 
} 

은 크롬에서 추적되면, IdentityServer 동의 화면에서 '예, 허용'을 클릭 한 후이 문제는 내 클라이언트의 웹 사이트에 의한 것처럼

Chrome network trace

답변

3

그래서 보인다 SSL을 종료 nginx 프론트 엔드 뒤에있다. this GitHub issue을 참조

, 나는 내 웹 사이트의 응용 프로그램 구성의 시작에 다음과 같은 추가 :

app.Use(async (ctx, next) => 
{ 
    string proto = ctx.Request.Headers.Get("X-Forwarded-Proto"); 
    if (!string.IsNullOrEmpty(proto)) 
    { 
     ctx.Request.Scheme = proto; 
    } 
    await next(); 
}); 

이 들어오는 요청이 HTTPS를 통해이라고 웹 사이트 인식하게를; 이는 IdentityServer3 미들웨어가 https URI를 생성하도록 보장합니다.