-
Notifications
You must be signed in to change notification settings - Fork 191
Add AuthenticationProperties to AuthenticateResult for failures. #889
Conversation
Bleh why don't you create a real first class AuthenticationError class with the things you want, that can contain a Properties if you want, but not just a top level properties |
How's this? |
Do we really need properties, or just a dictionary bag? Or are we storing original properties? |
@@ -31,12 +31,17 @@ public class AuthenticateResult | |||
/// <summary> | |||
/// Additional state values for the authentication session. | |||
/// </summary> | |||
public AuthenticationProperties Properties => Ticket?.Properties; | |||
public AuthenticationProperties Properties => Ticket?.Properties ?? Error?.Properties; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will both of these ever be set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, get rid of this fallback, I think Properties should only be Ticket.Properties, make them go Error.Properties if they want the error ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we should just get rid of this property since there's potentially two Properties now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, this looks like a disaster waiting to happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will never be both a Ticket and an Error, and the Properties collection is actually the same either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe instead of an Error property, we should have ErrorResult derive from AuthenticateResult, have Ticket return null, Properties return the error properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So basically instead of a new standalone AuthenticationError class, have an ErrorResult : AuthenticateResult instead which sets the Result up properly (no ticket, properties only)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AuthError gives me a mechanic to solve the next problem (#1178) flowing error details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure but the Error is just an exception + properties, can't you do the same with an ErrorResult (which also has Failure exception + Properties)? Where's the relevant code in the associated PR today?
In this case it's the original auth properties from the user's challenge. |
8237e8a
to
508b1d6
Compare
bump rebased and revived for 2.1. We now have to be more careful that the changes are strictly additive. |
I think I'd prefer we added something like a generic bag to AuthenticateResult:
And then just have Security/RemoteAuthHandler put whatever it needs into the CustomData to flow the extra error info you need. AuthenticateError looks way too similar to AuthenticateResult... |
AuthProperties aren't custom data, they're auth flow state that we surface for success but not for failures. Your suggestion applies more to aspnet/Security#1178 (comment) than the current issue. |
There's already a Properties on AuthenticateResult |
Why can't security just manufacture an error AuthenticateResult with the correct Properties inside? |
{ | ||
return new AuthenticateResult() { Failure = new Exception(failureMessage) }; | ||
return new AuthenticateResult() { Error = new AuthenticationError(failure, properties) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically instead of adding an Error, just add a new _errorProperties field to use here, and return that instead of _Error.Properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually scratch that, I'd just leave Properties to mean Ticket.Properties, and add a new FailureProperties so its clear they aren't the same thing...no confusing fallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are the same properties. We just don't have a way to surface them for failure scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A field can still work, just copy the properties into the field in both Success and Failure instead of calling through to the Ticket/Error.
My main pushback is AuthenticateResult is already meant to handle errors. We don't need another AuthenticationError class
AuthenticateResult.Properties requires an AuthTicket, which requires a ClaimsPrincipal. |
508b1d6
to
95a7a6a
Compare
Updated, this version's a little simpler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better :)
95a7a6a
to
321639b
Compare
aspnet/Security#1188
See the matching Security PR.
@HaoK how crazy is this? I know you just finished cleaning these up.