Azure ADを使用するC#アプリケーションを作成しました。以下は私のStartup.Auth.csファイルです。私がドメインに接続しているときは、すべて正常に動作します。しかし、ドメインにいないときにUser.IsInRole
を使用すると、信頼関係エラーが発生します。何が原因だろうか?Azure AD RBAC User.IsInRoleがドメインにないときに信頼関係エラーをスローする
さらに:を使用してください。[Authorize(Roles="MyRole")]
WORKS! 正確なエラーは次のとおりです。The trust relationship between this workstation and the primary domain failed.
// Startup.Auth.cs
private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
private static string tenantId = ConfigurationManager.AppSettings["ida:TenantId"];
private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];
private static string redirectUri = ConfigurationManager.AppSettings["ida:RedirectUri"];
string authority = aadInstance + tenantId;
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
RedirectUri = redirectUri,
TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters()
{
ValidateIssuer = true, // For Single-Tenant App.
RoleClaimType = "roles" // Grab roles when user authenticates.
},
Notifications = new OpenIdConnectAuthenticationNotifications()
{
AuthenticationFailed = (context) =>
{
return System.Threading.Tasks.Task.FromResult(0);
}
}
});
// This makes any middleware defined above this line run before the Authorization rule is applied in web.config
app.UseStageMarker(PipelineStage.Authenticate);
}