2017-09-04 4 views
2

私はIdentityServer3で保護しようとしている非常に単純なMVC5のWebサイトを持っています。なぜIdentityServerはhttpsではなくhttpにリダイレクトされますか?

私のウェブサイトと私のIdentityServerインスタンスの両方がAppHarborで別々のサイトとしてホストされています。どちらもhttpsの後ろにあります。

[Authorize]属性(例:/Home/About)で保護されている自分のウェブサイトのリソースにヒットした場合、正常にIdentityServerにリダイレクトされ、正常に認証できます。

IdentityServerがWebサイトに返信すると(app.FormPostResponse.jsを介して)、Webサイトは要求されたリソースへの302リダイレクトで応答します。しかし、このリダイレクトはへのhttp、ないHTTPS(下のネットワークトレースを参照)です。

私は、これはちょうど私の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>(); 
    } 
} 

はStartup.csは私のIdentityServer3インスタンスからである。ここでは

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からのトレースです:

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を確実に生成するように見えます。

関連する問題