// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Security.Claims; using Microsoft.AspNetCore.Http; namespace Microsoft.AspNetCore.Authentication { /// /// Base context for events that produce AuthenticateResults. /// public abstract class ResultContext : BaseContext where TOptions : AuthenticationSchemeOptions { /// /// Constructor. /// /// The context. /// The authentication scheme. /// The authentication options associated with the scheme. protected ResultContext(HttpContext context, AuthenticationScheme scheme, TOptions options) : base(context, scheme, options) { } /// /// Gets or sets the containing the user claims. /// public ClaimsPrincipal Principal { get; set; } private AuthenticationProperties _properties; /// /// Gets or sets the . /// public AuthenticationProperties Properties { get => _properties ?? (_properties = new AuthenticationProperties()); set => _properties = value; } /// /// Gets the result. /// public AuthenticateResult Result { get; private set; } /// /// Calls success creating a ticket with the and . /// public void Success() => Result = HandleRequestResult.Success(new AuthenticationTicket(Principal, Properties, Scheme.Name)); /// /// Indicates that there was no information returned for this authentication scheme. /// public void NoResult() => Result = AuthenticateResult.NoResult(); /// /// Indicates that there was a failure during authentication. /// /// public void Fail(Exception failure) => Result = AuthenticateResult.Fail(failure); /// /// Indicates that there was a failure during authentication. /// /// public void Fail(string failureMessage) => Result = AuthenticateResult.Fail(failureMessage); } }