我正在尝试将用于身份验证的Azure AD与Piranha CMS集成在一起。
到目前为止,这是我的配置:
启动
public IServiceProvider ConfigureServices(IServiceCollection services) {
services.AddPiranhaImageSharp();
services.AddPiranhaEF(options => options.UseMySql(Configuration["ConnectionStrings:DefaultConnection"]));
services.AddPiranhaIdentityWithSeed<IdentityMySQLDb>(
options => options.UseMySql(Configuration["ConnectionStrings:DefaultConnection"]));
services.AddPiranhaManager();
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
}).AddOpenIdConnect(options =>
{
options.Authority = "https://login.microsoftonline.com/" + this.TenantId;
options.ClientId = this.ClientId;
options.ResponseType = OpenIdConnectResponseType.IdToken;
options.CallbackPath = "/signin-callback";
options.SignedOutRedirectUri = "https://localhost:5001/";
options.SaveTokens = true;
options.Events.OnTokenValidated = async context => { await TokenValidated(context); };
}).AddCookie();
}
通过上述配置,我设法使用Azure AD对公共网站的用户进行身份验证。
当我尝试访问 manager 区域时,无法使用默认的用户/密码组合访问它。这是我需要帮助的地方。
稍后编辑:
为了使两者都能正常工作,我进行了以下更改:
services.AddAuthentication(/*specify no options, leave defaults*/)
.AddOpenIdConnect(options =>
{
options.Authority = "https://login.microsoftonline.com/" + this.TenantId;
options.ClientId = this.ClientId;
options.ResponseType = OpenIdConnectResponseType.IdToken;
options.CallbackPath = "/signin-callback";
options.RemoteSignOutPath = "/signout-oidc";
options.SignedOutRedirectUri = "https://localhost:5001/";
options.SignedOutCallbackPath = "/signout-callback";
options.SignOutScheme = OpenIdConnectDefaults.AuthenticationScheme;
options.Events.OnTokenValidated = async context => { await TokenValidated(context); };
})
.AddCookie(options => options.Cookie.SameSite = SameSiteMode.None);
然后,当我尝试登录/注销时,我创建了一个SecurityController,如下所示:
public class SecurityController : Controller
{
public IActionResult Login()
{
return Challenge(new AuthenticationProperties
{
RedirectUri = "/about"
}, OpenIdConnectDefaults.AuthenticationScheme);
}
public async Task<IActionResult> Logout()
{
await HttpContext.SignOutAsync("Identity.External");
return Redirect("/");
}
}
答案 0 :(得分:0)
方法AddPiranhaIdentityWithSeed
具有两个可选参数,用于设置身份选项和 Cookie选项,但是由于您未提供这些参数,因此该方法正在设置默认值选项。由于这些内容可能会干扰您稍后添加的选项,因此您可能想覆盖这些设置,因此请在此处查看文档:
http://piranhacms.org/docs/components/authentication/identity-security
此外,为了使用户能够访问经理,有一个一整批声明,这些声明指定了您需要添加到本地身份用户的用户可以执行的操作。您可以在这里阅读有关它们的信息:
http://piranhacms.org/docs/components/authentication
最诚挚的问候
Håkan