I am trying to integrate Azure AD for authentication with a Piranha CMS.
This is my configuration so far:
Startup
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();
}
With the above configuration, I managed to use Azure AD to authenticate users for the public website.
When i am trying to access the manager area, i am unable to access it using the default user/pass combo. This is where i would need a bit of help.
Later Edit:
In order to get both working i have made the following changes:
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);
Then when I try and login/logout, I have created a SecurityController as follows:
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("/");
}
}