Skip to content

Reuse failed auth results in AuthN - #43269

Merged
Tratcher merged 1 commit into
dotnet:mainfrom
Kahbazi:kahbazi/ReuseAuthResults
Aug 15, 2022
Merged

Tratcher merged 1 commit into
dotnet:mainfrom
Kahbazi:kahbazi/ReuseAuthResults

Conversation

@Kahbazi

@Kahbazi Kahbazi commented Aug 13, 2022

Copy link
Copy Markdown
Member

No description provided.

@Kahbazi
Kahbazi requested a review from Tratcher as a code owner August 13, 2022 20:16
@ghost ghost added area-auth Includes: authentication, authorization, OAuth, OIDC, and access token validation community-contribution Indicates that the PR has been added by a community member labels Aug 13, 2022
@ghost

ghost commented Aug 13, 2022

Copy link
Copy Markdown

Thanks for your PR, @Kahbazi. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@davidfowl davidfowl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keep these changes coming 👍🏾

@davidfowl davidfowl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Turns out you can mutate these results 😢

@Kahbazi

Kahbazi commented Aug 14, 2022

Copy link
Copy Markdown
Member Author

Turns out you can mutate these results 😢

I can't see how! Could you please elaborate? Is it because of the Exception object? I would argue that even in the clone method the Exception remains the same instance.

@Tratcher Tratcher left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you change AuthenticateResult.NoResult to cache?

There's a theoretical issue with caching AuthenticateResult, it can reference mutable structures like ClaimsPrincipal, AuthenticationProerties, Exception, etc.. NoResult, Skipped, and Handled might be the only cases truly safe to cache because they don't hold any mutable objects. That might be worth overlooking for extremely common scenarios. Are any of these failures especially common?

edit Oh, already discussed above 😁.

(Merged since the feedback was trivial and we're at the rc1 deadline)


internal static class AuthenticateResults
{
internal static AuthenticateResult NoSelfSigned = AuthenticateResult.Fail("Options do not allow self signed certificates.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Style: Why define these in separate classes if they're only used in one class?

/// </summary>
public class HandleRequestResult : AuthenticateResult
{
private static readonly HandleRequestResult _noResult = new() { None = true };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Style: I think we use "NoResult" for class statics, and "_noResult" for class fields.

@Tratcher
Tratcher merged commit 1b15d0e into dotnet:main Aug 15, 2022
@ghost ghost added this to the 7.0-rc1 milestone Aug 15, 2022
@Kahbazi
Kahbazi deleted the kahbazi/ReuseAuthResults branch August 16, 2022 05:05
@Kahbazi

Kahbazi commented Aug 16, 2022

Copy link
Copy Markdown
Member Author

Can you change AuthenticateResult.NoResult to cache?

@Tratcher I've done that in this PR #43268

@ghost

ghost commented Aug 16, 2022

Copy link
Copy Markdown

Hi @Kahbazi. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-auth Includes: authentication, authorization, OAuth, OIDC, and access token validation community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants