Merge branch 'release/2.1' into dev

This commit is contained in:
Javier Calvarro Nelson 2018-02-09 13:39:09 -08:00
commit 7a1f716fc0
5 changed files with 44 additions and 59 deletions

View File

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

View File

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