2016-11-23 6 views
2

私はIDサーバーを初めて使用しており、開発時にセットアップしています。ほとんどの場合、単一のノードを使用する場合に機能します。私が5つのノードに切り替えると、時にはうまくいくことがあります。サービスファブリックとアイデンティティサーバー4

ユーザーのクレームからユーザーの役割を取得する機能を持つベースコントローラーを拡張するコントローラーにAuthorize属性があります。私は(ヘッダーにトークンを持つ)認可の呼び出しを行う際に起こるん何

protected string GetUserRole() 
    { 
     var roleClaim = User.Claims.SingleOrDefault(c => c.Type == "role"); 

     if (roleClaim == null) 
     { 
      throw new ArgumentNullException("Cant find role claim on: " + Request.Host.Host); 
     } 
     else 
     { 
      return roleClaim.Value; 
     } 
    } 

は、それがクラッシュしたときにroleClaimがnullであるということです。私はその後、電話をかけようとしましたが、今度は無許可で同じ結果を得ました。

これは私のAPIのための設定です:アイデンティティ・サーバー用の

app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions 
     { 
      Authority = "http://localhost:19081/App/Identity", 
      ScopeName = "api1", 
      RequireHttpsMetadata = false, 
      AutomaticAuthenticate = true 
     }); 

は、構成:

var cert = new X509Certificate2(Path.Combine(_contentRoot, "damienbodserver.pfx"), ""); 
     services.AddDeveloperIdentityServer() 
      .SetSigningCredential(cert) 
      .AddInMemoryScopes(Scopes.Get()) 
      .AddInMemoryClients(Clients.Get()) 
      .AddResourceOwnerValidator<ResourceOwnerPasswordValidator>() 
      .AddProfileService<ProfileService>(); 

     services.AddMvc(); 

私のクライアント:

public static IEnumerable<Client> Get() 
    { 
     return new[] 
     { 
      new Client() 
      { 
       ClientId = "myapi", 
       ClientSecrets = new List<Secret> 
       { 
        new Secret("secret".Sha256()) 
       }, 
       ClientName = "My Beautiful Api", 
       AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, 
       AllowAccessTokensViaBrowser = true, 
       RequireConsent = false, 
       AllowedScopes = { 
        "openid", 
        "api1" 
       }, 
       AllowedCorsOrigins = new List<string> { 
        "*" 
       }, 
       Enabled = true 
      } 
     }; 
    } 
} 

と範囲:

public static IEnumerable<Scope> Get() 
    { 
     return new List<Scope> 
     { 
      StandardScopes.OpenId, 
      StandardScopes.ProfileAlwaysInclude, 
      StandardScopes.EmailAlwaysInclude, 
      StandardScopes.OfflineAccess, 
      StandardScopes.RolesAlwaysInclude, 
      new Scope 
      { 
       Name = "api1", 
       DisplayName = "API 1", 
       Description = "API 1 features and data", 
       Type = ScopeType.Resource, 
       ScopeSecrets = new List<Secret> 
       { 
        new Secret("secret".Sha256()) 
       }, 
       Claims = new List<ScopeClaim> 
       { 
        new ScopeClaim("role") 
       } 
      } 
     }; 
    } 

私はドキュメントを読もうとしましたが、多くのものが見つからないようですので、私の質問は最初です。

なぜ時々roleClaimが存在するのですか?

と第二:

許可と私は、コントローラの[オーソライズ]を持っていないのに、なぜアイデンティティサーバーが401のステータスコードで応答しませんか?

答えて

0

Service FabricとIdentity Serverをサービスとして使用する場合は、状態とメモリ内のストレージに関する問題が発生している可能性があります。 Leveraging Service Fabricは、従来のモノリシックなアーキテクチャアプローチに比べてさまざまな利点を提供します。もしまだあなたがいないなら、私はあなたがステートレスなアプローチを提供することに焦点を当てて、本当にJSON Webトークン(JWT)のドキュメントを読んでいます。これにより、このトークンを暗号化および復号化して、重要なユーザー/有効期限情報を提供または読み取ることにより、迅速な解決策を提供できます。

関連する問題