Fix B2C templates

This commit is contained in:
Javier Calvarro Nelson 2018-02-08 18:41:14 -08:00
parent 06f1340f2a
commit 67cf534bda
5 changed files with 44 additions and 59 deletions

View File

@ -34,7 +34,7 @@
] ]
}, },
{ {
"condition": "(!OrganizationalAuth)", "condition": "(!OrganizationalAuth && !IndividualB2CAuth)",
"exclude": [ "exclude": [
"Controllers/**", "Controllers/**",
"Pages/Account/**", "Pages/Account/**",
@ -78,12 +78,6 @@
"exclude": [ "exclude": [
"Extensions/AzureAdB2C*.cs" "Extensions/AzureAdB2C*.cs"
] ]
},
{
"condition": "(!OrganizationalAuth || !IndividualB2CAuth)",
"exclude": [
"Controllers/AccountController.cs"
]
} }
] ]
} }

View File

@ -0,0 +1,10 @@
@page
@model AccessDeniedModel
@{
ViewData["Title"] = "Access denied";
}
<header>
<h1 class="text-danger">@ViewData["Title"]</h1>
<p class="text-danger">You do not have access to this resource.</p>
</header>

View File

@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace Company.WebApplication1.Pages.Account
{
public class AccessDeniedModel : PageModel
{
public void OnGet()
{
}
}
}

View File

@ -33,7 +33,7 @@
] ]
}, },
{ {
"condition": "(!IndividualAuth && !OrganizationalAuth)", "condition": "(!IndividualAuth && !OrganizationalAuth && !IndividualB2CAuth)",
"exclude": [ "exclude": [
"Controllers/AccountController.cs", "Controllers/AccountController.cs",
"Views/Account/**", "Views/Account/**",

View File

@ -1,24 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
#if (IndividualAuth)
using System.Security.Claims;
#endif
using System.Threading.Tasks; using System.Threading.Tasks;
#if (OrganizationalAuth || IndividualB2CAuth || IndividualAuth)
using Microsoft.AspNetCore.Authentication;
#endif
#if (OrganizationalAuth || IndividualB2CAuth) #if (OrganizationalAuth || IndividualB2CAuth)
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.AspNetCore.Authentication.OpenIdConnect;
#endif #endif
#if (IndividualAuth)
using Microsoft.AspNetCore.Authorization;
#endif
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
#if (IndividualAuth) #if (IndividualB2CAuth)
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
#endif #endif
@ -31,35 +21,23 @@ namespace Company.WebApplication1.Controllers
[HttpGet] [HttpGet]
public IActionResult SignIn() public IActionResult SignIn()
{ {
var redirectUrl = Url.Action(nameof(HomeController.Index), "Home"); var redirectUrl = Url.Page("/Index");
return Challenge( return Challenge(
new AuthenticationProperties { RedirectUri = redirectUrl }, new AuthenticationProperties { RedirectUri = redirectUrl },
OpenIdConnectDefaults.AuthenticationScheme); OpenIdConnectDefaults.AuthenticationScheme
);
} }
[HttpGet] [HttpGet]
public IActionResult SignOut() public IActionResult SignOut()
{ {
var callbackUrl = Url.Action(nameof(SignedOut), "Account", values: null, protocol: Request.Scheme); var callbackUrl = Url.Page("/Account/SignedOut", pageHandler: null, values: null, protocol: Request.Scheme);
return SignOut( return SignOut(
new AuthenticationProperties { RedirectUri = callbackUrl }, new AuthenticationProperties { RedirectUri = callbackUrl },
CookieAuthenticationDefaults.AuthenticationScheme, CookieAuthenticationDefaults.AuthenticationScheme, OpenIdConnectDefaults.AuthenticationScheme
OpenIdConnectDefaults.AuthenticationScheme); );
} }
#elseif (IndividualB2CAuth)
[HttpGet]
public IActionResult SignedOut()
{
if (User.Identity.IsAuthenticated)
{
// Redirect to home page if the user is authenticated.
return RedirectToAction(nameof(HomeController.Index), "Home");
}
return View();
}
#endif
#if (IndividualB2CAuth)
private readonly AzureAdB2COptions _options; private readonly AzureAdB2COptions _options;
public AccountController(IOptions<AzureAdB2COptions> b2cOptions) public AccountController(IOptions<AzureAdB2COptions> b2cOptions)
@ -70,16 +48,17 @@ namespace Company.WebApplication1.Controllers
[HttpGet] [HttpGet]
public IActionResult SignIn() public IActionResult SignIn()
{ {
var redirectUrl = Url.Action(nameof(HomeController.Index), "Home"); var redirectUrl = Url.Page("/Index");
return Challenge( return Challenge(
new AuthenticationProperties { RedirectUri = redirectUrl }, new AuthenticationProperties { RedirectUri = redirectUrl },
OpenIdConnectDefaults.AuthenticationScheme); OpenIdConnectDefaults.AuthenticationScheme
);
} }
[HttpGet] [HttpGet]
public IActionResult ResetPassword() public IActionResult ResetPassword()
{ {
var redirectUrl = Url.Action(nameof(HomeController.Index), "Home"); var redirectUrl = Url.Page("/Index");
var properties = new AuthenticationProperties { RedirectUri = redirectUrl }; var properties = new AuthenticationProperties { RedirectUri = redirectUrl };
properties.Items[AzureAdB2COptions.PolicyAuthenticationProperty] = _options.ResetPasswordPolicyId; properties.Items[AzureAdB2COptions.PolicyAuthenticationProperty] = _options.ResetPasswordPolicyId;
return Challenge(properties, OpenIdConnectDefaults.AuthenticationScheme); return Challenge(properties, OpenIdConnectDefaults.AuthenticationScheme);
@ -88,7 +67,7 @@ namespace Company.WebApplication1.Controllers
[HttpGet] [HttpGet]
public IActionResult EditProfile() public IActionResult EditProfile()
{ {
var redirectUrl = Url.Action(nameof(HomeController.Index), "Home"); var redirectUrl = Url.Page("/Index");
var properties = new AuthenticationProperties { RedirectUri = redirectUrl }; var properties = new AuthenticationProperties { RedirectUri = redirectUrl };
properties.Items[AzureAdB2COptions.PolicyAuthenticationProperty] = _options.EditProfilePolicyId; properties.Items[AzureAdB2COptions.PolicyAuthenticationProperty] = _options.EditProfilePolicyId;
return Challenge(properties, OpenIdConnectDefaults.AuthenticationScheme); return Challenge(properties, OpenIdConnectDefaults.AuthenticationScheme);
@ -97,21 +76,12 @@ namespace Company.WebApplication1.Controllers
[HttpGet] [HttpGet]
public IActionResult SignOut() public IActionResult SignOut()
{ {
var callbackUrl = Url.Action(nameof(SignedOut), "Account", values: null, protocol: Request.Scheme); var callbackUrl = Url.Page("/Account/SignedOut", pageHandler: null, values: null, protocol: Request.Scheme);
return SignOut(new AuthenticationProperties { RedirectUri = callbackUrl }, return SignOut(
CookieAuthenticationDefaults.AuthenticationScheme, OpenIdConnectDefaults.AuthenticationScheme); new AuthenticationProperties { RedirectUri = callbackUrl },
} CookieAuthenticationDefaults.AuthenticationScheme,
OpenIdConnectDefaults.AuthenticationScheme
[HttpGet] );
public IActionResult SignedOut()
{
if (User.Identity.IsAuthenticated)
{
// Redirect to home page if the user is authenticated.
return RedirectToAction(nameof(HomeController.Index), "Home");
}
return View();
} }
#endif #endif
@ -121,4 +91,4 @@ namespace Company.WebApplication1.Controllers
return View(); return View();
} }
} }
} }