私は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のステータスコードで応答しませんか?