Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit fd597b9

Browse files
committed
Add AuthenticationProperties to AuthenticateResult for failures.
1 parent 49f3777 commit fd597b9

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

src/Microsoft.AspNetCore.Authentication.Abstractions/AuthenticateResult.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ protected AuthenticateResult() { }
3131
/// <summary>
3232
/// Additional state values for the authentication session.
3333
/// </summary>
34-
public AuthenticationProperties Properties => Ticket?.Properties;
34+
public AuthenticationProperties Properties => Ticket?.Properties ?? Error?.Properties;
3535

3636
/// <summary>
3737
/// Holds failure information from the authentication.
3838
/// </summary>
39-
public Exception Failure { get; protected set; }
39+
public Exception Failure => Error?.Failure;
40+
41+
/// <summary>
42+
/// Holds error information from the authentication.
43+
/// </summary>
44+
public AuthenticationError Error { get; protected set; }
4045

4146
/// <summary>
4247
/// Indicates that there was no information returned for this authentication scheme.
@@ -73,17 +78,35 @@ public static AuthenticateResult NoResult()
7378
/// <returns>The result.</returns>
7479
public static AuthenticateResult Fail(Exception failure)
7580
{
76-
return new AuthenticateResult() { Failure = failure };
81+
return new AuthenticateResult() { Error = new AuthenticationError(failure) };
7782
}
7883

7984
/// <summary>
8085
/// Indicates that there was a failure during authentication.
8186
/// </summary>
82-
/// <param name="failureMessage">The failure message.</param>
87+
/// <param name="failure">The failure exception.</param>
88+
/// <param name="properties">Additional state values for the authentication session.</param>
8389
/// <returns>The result.</returns>
84-
public static AuthenticateResult Fail(string failureMessage)
90+
public static AuthenticateResult Fail(Exception failure, AuthenticationProperties properties)
8591
{
86-
return new AuthenticateResult() { Failure = new Exception(failureMessage) };
92+
return new AuthenticateResult() { Error = new AuthenticationError(failure, properties) };
8793
}
94+
95+
/// <summary>
96+
/// Indicates that there was a failure during authentication.
97+
/// </summary>
98+
/// <param name="failureMessage">The failure message.</param>
99+
/// <returns>The result.</returns>
100+
public static AuthenticateResult Fail(string failureMessage)
101+
=> Fail(new Exception(failureMessage));
102+
103+
/// <summary>
104+
/// Indicates that there was a failure during authentication.
105+
/// </summary>
106+
/// <param name="failureMessage">The failure message.</param>
107+
/// <param name="properties">Additional state values for the authentication session.</param>
108+
/// <returns>The result.</returns>
109+
public static AuthenticateResult Fail(string failureMessage, AuthenticationProperties properties)
110+
=> Fail(new Exception(failureMessage), properties);
88111
}
89112
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
6+
namespace Microsoft.AspNetCore.Authentication
7+
{
8+
public class AuthenticationError
9+
{
10+
public AuthenticationError(Exception failure)
11+
{
12+
Failure = failure ?? throw new ArgumentNullException(nameof(failure));
13+
}
14+
15+
public AuthenticationError(Exception failure, AuthenticationProperties properties)
16+
: this(failure)
17+
{
18+
Properties = properties;
19+
}
20+
21+
/// <summary>
22+
/// Holds failure information from the authentication.
23+
/// </summary>
24+
public Exception Failure { get; }
25+
26+
/// <summary>
27+
/// Additional state values for the authentication session.
28+
/// </summary>
29+
public AuthenticationProperties Properties { get; }
30+
}
31+
}

0 commit comments

Comments
 (0)