diff --git a/src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticateResult.cs b/src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticateResult.cs index 1da6a0b94d..5982143bcb 100644 --- a/src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticateResult.cs +++ b/src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticateResult.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Authentication /// /// Additional state values for the authentication session. /// - public AuthenticationProperties Properties => Ticket?.Properties; + public AuthenticationProperties Properties { get; protected set; } /// /// Holds failure information from the authentication. @@ -54,7 +54,7 @@ namespace Microsoft.AspNetCore.Authentication { throw new ArgumentNullException(nameof(ticket)); } - return new AuthenticateResult() { Ticket = ticket }; + return new AuthenticateResult() { Ticket = ticket, Properties = ticket.Properties }; } /// @@ -76,14 +76,32 @@ namespace Microsoft.AspNetCore.Authentication return new AuthenticateResult() { Failure = failure }; } + /// + /// Indicates that there was a failure during authentication. + /// + /// The failure exception. + /// Additional state values for the authentication session. + /// The result. + public static AuthenticateResult Fail(Exception failure, AuthenticationProperties properties) + { + return new AuthenticateResult() { Failure = failure, Properties = properties }; + } + /// /// Indicates that there was a failure during authentication. /// /// The failure message. /// The result. public static AuthenticateResult Fail(string failureMessage) - { - return new AuthenticateResult() { Failure = new Exception(failureMessage) }; - } + => Fail(new Exception(failureMessage)); + + /// + /// Indicates that there was a failure during authentication. + /// + /// The failure message. + /// Additional state values for the authentication session. + /// The result. + public static AuthenticateResult Fail(string failureMessage, AuthenticationProperties properties) + => Fail(new Exception(failureMessage), properties); } }