我正在创建一个使用 azure AD B2C 进行身份验证的 asp net core 2 web api。我想使用 AD B2C 组将某些控制器的使用限制为管理员成员。
我已经明白,目前实现这一目标的唯一方法是访问图形 API 并将一些角色声明添加到用户的声明中。
但是我在启动时查询图形 api 时遇到了麻烦。
我的ConfigureService方法是这样的:
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddAzureAdB2C(options => Configuration.Bind("AzureAdB2C", options))
.AddJwtBearer(options => {
options.Authority = string.Format("https://login.microsoftonline.com/tfp/{0}/{1}/v2.0/", "b2ctenant.onmicrosoft.com", "B2C_1_DefaultSignUpIn");
options.Audience = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx";
options.Events = new JwtBearerEvents
{
OnTokenValidated = OnAuthorizationCodeReceived,
};
})
.AddCookie(options =>
{
options.LoginPath = "/Account/SignIn";
options.LogoutPath = "/Account/SignOut";
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
options.Events = new CookieAuthenticationEvents
{
OnRedirectToLogin = OnRedirectToLogin
};
}); …Run Code Online (Sandbox Code Playgroud) azure-ad-graph-api azure-ad-b2c asp.net-core-webapi asp.net-core-2.0
我目前遇到EF核心2.1和本机客户端用来更新包含多层嵌入对象的对象的web api的问题.我已经阅读了这两个主题:
https://docs.microsoft.com/en-us/ef/core/saving/disconnected-entities
我已经了解到,现在更新EF Core 2中的对象确实不是那么明显.但我还没有设法找到一个有效的解决方案.在每次尝试时,我都有一个例外,告诉我EF已经跟踪了"步骤".
我的模型看起来像这样:
//CIApplication the root class I’m trying to update
public class CIApplication : ConfigurationItem // -> derive of BaseEntity which holds the ID and some other properties
{
//Collection of DeploymentScenario
public virtual ICollection<DeploymentScenario> DeploymentScenarios { get; set; }
//Collection of SoftwareMeteringRules
public virtual ICollection<SoftwareMeteringRule> SoftwareMeteringRules { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
//与应用程序具有一对多关系的部署方案.部署方案包含两个步骤列表
public class DeploymentScenario : BaseEntity
{
//Collection of substeps
public virtual ICollection<Step> InstallSteps { get; set; }
public virtual ICollection<Step> UninstallSteps …Run Code Online (Sandbox Code Playgroud)