ext method for authn back office scheme with null check, fixing tests

This commit is contained in:
Shannon
2020-12-02 15:49:28 +11:00
parent e297bc8c8d
commit d0e17d16bc
4 changed files with 26 additions and 7 deletions

View File

@@ -1,10 +1,29 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Core;
namespace Umbraco.Extensions
{
public static class ControllerExtensions
{
/// <summary>
/// Runs the authentication process
/// </summary>
/// <param name="controller"></param>
/// <returns></returns>
public static async Task<AuthenticateResult> AuthenticateBackOfficeAsync(this ControllerBase controller)
{
if (controller.HttpContext == null)
{
return AuthenticateResult.NoResult();
}
var result = await controller.HttpContext.AuthenticateAsync(Constants.Security.BackOfficeAuthenticationType);
return result;
}
/// <summary>
/// Return the controller name from the controller type
/// </summary>