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

Add AuthenticationProperties to AuthenticateResult for failures. #889

Merged
merged 1 commit into from
Sep 27, 2017

Conversation

Tratcher
Copy link
Member

@Tratcher Tratcher commented Jul 6, 2017

aspnet/Security#1188
See the matching Security PR.

@HaoK how crazy is this? I know you just finished cleaning these up.

@HaoK
Copy link
Member

HaoK commented Jul 6, 2017

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

@Tratcher
Copy link
Member Author

Tratcher commented Jul 6, 2017

How's this?

@HaoK
Copy link
Member

HaoK commented Jul 6, 2017

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;
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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)

Copy link
Member Author

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.

Copy link
Member

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?

@Tratcher
Copy link
Member Author

Tratcher commented Jul 7, 2017

In this case it's the original auth properties from the user's challenge.

@Tratcher
Copy link
Member Author

bump rebased and revived for 2.1. We now have to be more careful that the changes are strictly additive.

@HaoK
Copy link
Member

HaoK commented Sep 26, 2017

I think I'd prefer we added something like a generic bag to AuthenticateResult:

   public Dictionary<string, object> CustomData { get } = new Dictionary<string, object>();

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...

@Tratcher
Copy link
Member Author

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.

@HaoK
Copy link
Member

HaoK commented Sep 26, 2017

There's already a Properties on AuthenticateResult

@HaoK
Copy link
Member

HaoK commented Sep 26, 2017

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) };
Copy link
Member

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

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

@HaoK HaoK Sep 26, 2017

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

@Tratcher
Copy link
Member Author

AuthenticateResult.Properties requires an AuthTicket, which requires a ClaimsPrincipal.

@Tratcher
Copy link
Member Author

Updated, this version's a little simpler.

Copy link
Member

@HaoK HaoK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better :)

@Tratcher Tratcher merged commit 321639b into dev Sep 27, 2017
@Tratcher Tratcher deleted the tratcher/fail branch September 27, 2017 21:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants