2017-10-23 4 views
2

私は、nginxプロキシの背後にあるDockerコンテナで実行しようとしているIdentityServer4インスタンスがあります。私はGitのレポからASPNETアイデンティティサンプルの上に基づいていますが、ユーザーが正常に私はIdentityServerとログから「エラーが発生しました」を得る新しいアカウントを登録後、マイStartup.csIdentityServer4 - サブクレームがありません

[07:46:39 ERR] An unhandled exception has occurred: sub claim is missing System.InvalidOperationException: sub claim is missing at IdentityServer4.IdentityServerPrincipal.AssertRequiredClaims(ClaimsPrincipal principal at IdentityServer4.Hosting.IdentityServerAuthenticationService.AugmentPrincipal(ClaimsPrincipal principal at IdentityServer4.Hosting.IdentityServerAuthenticationService.<SignInAsync>d__7.MoveNext

を示してきましたこのように見える

var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName(). 
var connectionString = Configuration.GetConnectionString("DefaultConnection"); 
var issuerUri = Configuration.GetSection("IssuerUri").Value; 

services.AddDbContext<ApplicationDbContext>(options => 
    options.UseSqlServer(connectionString)); 

services.AddIdentity<ApplicationUser, IdentityRole>() 
    .AddEntityFrameworkStores<ApplicationDbContext>() 
    .AddDefaultTokenProviders(); 

services.AddTransient<IEmailSender, EmailSender>(); 

services.AddMvc(); 

services.AddCors(o => o.AddPolicy("CorsPolicy", b => 
{ 
    b.AllowAnyOrigin() 
     .AllowAnyMethod() 
     .AllowAnyHeader(); 
})); 

services.AddIdentityServer(options => 
{ 
    options.IssuerUri = issuerUri; 
    options.PublicOrigin = issuerUri; 
}) 
.AddDeveloperSigningCredential() 

// this adds the config data from DB (clients, resources) 
.AddConfigurationStore(options => 
{ 
    options.ConfigureDbContext = builder => 
     builder.UseSqlServer(connectionString, 
      sql => sql.MigrationsAssembly(migrationsAssembly)); 
}) 

// this adds the operational data from DB (codes, tokens, consents) 
.AddOperationalStore(options => 
{ 
    options.ConfigureDbContext = builder => 
     builder.UseSqlServer(connectionString, 
      sql => sql.MigrationsAssembly(migrationsAssembly)); 

    // this enables automatic token cleanup. this is optional. 
    //options.EnableTokenCleanup = true; 
    //options.TokenCleanupInterval = 30; 
}); 

私はいくつかの明確な設定を見逃しているに違いないが、どこに見えないのだろうか。何か案は?

更新 私はこれでいくつかの進歩を遂げ、初期のエラーを乗り越えてしまったようです。ユーザー今認証されているが、サインイン-oidcページは

[11:33:21 INF] Request starting HTTP/1.1 POST http://mvcportal.co.uk/signin-oidc application/x-www-form-urlencoded 1565 
[11:33:21 INF] AuthenticationScheme: Cookies signed in. 
[11:33:21 INF] Request finished in 684.8425ms 302 
[11:33:27 INF] Request starting HTTP/1.1 POST http://mvcportal.co.uk/signin-oidc application/x-www-form-urlencoded 1565 
[11:33:27 ERR] Message contains error: 'invalid_grant', error_description: 'error_description is null', error_uri: 'error_uri is null', status code '400'. 

エラーがスローされます私は、有効なJWTを持っているが、私はIDPは発行者と同じではありません注意してください。あれは正しいですか?

{ 
    "nbf": 1508758474, 
    "exp": 1508758774, 
    "iss": "http://myproxiedlogonsitebehindnginx.co.uk", 
    "aud": "mvc.portal", 
    "nonce": "636443552746808541.MGVjMzk2NTEtYmYwNS00NmQwLTllOTQtZDVjNjdlYTA2YWVlYTQ3Zjg1NjgtZDA1Yi00NDE0LWJiYmYtMjM4YzI1NjZlYTcx", 
    "iat": 1508758474, 
    "c_hash": "kG7wG8vSgRe5zdriHQ6iMA", 
    "sid": "c9410ee8f27b69c32e43d5ac3d407f37", 
    "sub": "e80fb854-cab2-4381-8057-19de0fea73f4", 
    "auth_time": 1508757008, 
    "idp": "local", 
    "amr": [ 
    "pwd" 
    ] 
} 

UPDATE 2 ことが

new Client 
{ 
    ClientId = "mvc.portal", 
    ClientName = "Customer Portal", 
    ClientUri = customerPortalBaseUri, 

    ClientSecrets = 
    { 
     new Secret("21f51463-f436-4a84-92ce-1b520dd63a81".Sha256()) 
    }, 

    AllowedGrantTypes = GrantTypes.HybridAndClientCredentials, 
    AllowAccessTokensViaBrowser = false, 

    RedirectUris = { $"{customerPortalBaseUri}/signin-oidc"}, 
    FrontChannelLogoutUri = $"{customerPortalBaseUri}/signout-oidc", 
    PostLogoutRedirectUris = { $"{customerPortalBaseUri}/signout-callback-oidc" }, 

    AllowOfflineAccess = true, 

    RequireConsent = false, 

    AllowedScopes = 
    { 
     IdentityServerConstants.StandardScopes.OpenId, 
     IdentityServerConstants.StandardScopes.Profile, 
     IdentityServerConstants.StandardScopes.Email 
    } 
} 

そして、これを場合に役立ちます。これは、idsrv上のクライアント構成であるので、

services.AddAuthentication(options => 
    { 
     options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; 
     options.DefaultChallengeScheme = "oidc"; 
    }) 
    .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme) 
    .AddOpenIdConnect("oidc", options => 
    { 
     options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; 
     options.Authority = "http://myproxiedlogonsitebehindnginx.co.uk"; 
     options.RequireHttpsMetadata = false; 
     options.ClientId = "mvc.portal"; 
     options.ClientSecret = "21f51463-f436-4a84-92ce-1b520dd63a81"; 
     options.ResponseType = "code id_token"; 
     options.SaveTokens = true; 
     options.GetClaimsFromUserInfoEndpoint = true; 
    }); 

UPDATE 3 クライアント/ポータルconfigです今私はそれが展開と関係があると確信しています。b私のローカルマシン上でmvcアプリケーションを実行するが、(nginxの背後にある)nginxの背後にあるコンテナにデプロイされたidsvrを使用すると、私は問題なく認証することができる。しかし、コンテナ化されたポータルのバージョンを試しても、私は再試行した場合、その後、私はこれを取得するアクションが記録さ:

[11:22:51 INF] Request starting HTTP/1.1 POST http://mvcportal.co.uk/signin-oidc application/x-www-form-urlencoded 1559 
[11:22:51 ERR] Message contains error: 'invalid_grant', error_description: 'error_description is null', error_uri: 'error_uri is null', status code '400'. 
[11:22:51 ERR] Exception occurred while processing message. 
Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectProtocolException: Message contains error: 'invalid_grant'], error_description: 'error_description is null', error_uri: 'error_uri is null'. 
+0

クライアント構成を共有し、クライアントがIdentityServer4に接続するように設定する方法を教えてください。確かに – aaronR

+0

。投稿を更新しました –

+0

両方のバージョンが同じデータベースを探していますか?そうでない場合は、構成にエラーがある可能性があります。 –

答えて

0

は、だから私は最終的にそれの底になりました。 nginxのではデフォルトのヘッダー制限は素晴らしいプレーしていないようだと私は502エラーを防止

proxy_buffer_size   128k; 
proxy_buffers    4 256k; 
proxy_busy_buffers_size 256k; 

行が含まれるようにnginxの設定ファイルの更新ログ upstream sent too big header while reading response header from upstream

でこれを発見し、それはすべての罰金認証します今。

関連する問題