-
Notifications
You must be signed in to change notification settings - Fork 597
Incorporate community feedback from https://github.com/aspnet/Security/pull/112 #276
Conversation
Looks good so far... |
I actually like this suggestion from the PR you refer to (assuming its true)... Rename OAuthBearerAuthenticationMiddleware => TokenAuthenticationMiddleware |
But I see lots of stuff that doesn't look general enough to call this TokenAuthenticationOptions in here though... with a bunch of OpenId stuff on there. |
Renaming the OAuth2 bearer middleware was not part of the plan simply because there was no consensus concerning my suggestion 😄 IMHO, the best approach (as explained here: #112 (comment) and here: #112 (comment)) would probably consist in splitting the current OAuth2 bearer middleware into 2 middleware:
|
_securityTokenValidators = value; | ||
} | ||
} | ||
public IList<ISecurityTokenValidator> SecurityTokenValidators { get; } = new List<ISecurityTokenValidator>(); |
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.
Why there is no setter on this? Same comment for TVP.
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.
Writable collection properties are generally considered as a bad practice: https://msdn.microsoft.com/fr-fr/library/ms182327(v=vs.140).aspx
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.
I have seen that rule many times, i find it leads to some odd code. How will a user set the validators they want to use? It is a little more cumbersome. I think that rule was written before the new syntax like: new foo { x = this, y = that ...} existed.
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.
Very easily, with Add
: https://github.com/aspnet/Security/pull/276/files#diff-b15c3246438a45f3bed149e5f60b1e22R144
And BTW, the object initializer syntax cannot be used anymore, as we're now using delegates to set the options:
app.UseCookieAuthentication(options => {
options.AutomaticAuthentication = true;
});
I do not understand the reason for this pull request. Are there any issues opened that this PR is addressing? |
@tushargupta51 see @brentschmaltz's previous PR: #112 Tons of things have been omitted and this PR only aims at incorporating them 😄 |
@PinpointTownes specifically what issues are you addressing? I see some formatting and style changes, some that break extensiblity, make the product more fragile. For example, if you can set Options.StateDataFormat to null, then any consumer of that property must expect that it can be null. Another example, setting timeout negative, what would be the result of that? Siting the .Net guidelines as a reason for a change seems to imply that following those guidelines is required for code changes. I don't think that is true. |
No particular issue, just formatting and style things you didn't include when you pushed your previous PR 😯
AGAIN, IT CANNOT BE NULL: a default format relying on the data protection block is automatically instantiated if you leave it to null.
But rules are there for a reason, and you need a reason to break them 😄 |
@brentschmaltz here's something I'd like to fix: https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationHandler.cs#L178 The bearer middleware shouldn't throw by default, as it returns a 500 response instead of a correct challenge. And it's bad, bad, bad 😄 |
/// </summary> | ||
public string Scope { get; 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.
Replaced by a list for consistency: https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions.cs#L92
Other things I'd like to fix:
|
Your points above:
|
I'm not saying that we shouldn't have these two properties (it's probably unavoidable BTW), but the way we're currently using them is just weird:
Being able to "dynamically" change the |
@brentschmaltz don't worry, I won't break your changes 😄 This PR needs to be rebased anyway. |
Rebased. I limited this PR to the code style issues we discussed in @brentschmaltz's PR (#112) and removed the controversial changes. This PR also replaces |
|
||
/// <summary> | ||
/// The object provided by the application to process events raised by the bearer authentication middleware. | ||
/// The application may implement the interface fully, or it may create an instance of OAuthBearerAuthenticationProvider | ||
/// and assign delegates only to the events it wants to process. | ||
/// </summary> | ||
public OAuthBearerAuthenticationNotifications Notifications { get; set; } | ||
public OAuthBearerAuthenticationNotifications Notifications { get; [param: NotNull] set; } = new OAuthBearerAuthenticationNotifications(); |
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.
FYI: we've been asked not to use NotNull in this context (more details coming soon). Let's revert back to setting these in the middleware constructor for 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.
Do you want me to revert all the inline properties? This syntax makes the code much clearer IMHO.
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.
You can keep those. We just don't want to put the non-null enforcement code here.
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.
Okay. param: NotNull
is currently used in a few places. Do you want me to remove them?
https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationOptions.cs#L41
https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNet.Authentication/Notifications/RedirectToIdentityProviderNotification.cs#L26
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.
Don't worry about the existing ones yet, just don't add more.
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.
Reverted.
⌚ Almost ready. |
@@ -38,16 +34,6 @@ public class OAuthBearerAuthenticationMiddleware : AuthenticationMiddleware<OAut | |||
ConfigureOptions<OAuthBearerAuthenticationOptions> configureOptions) | |||
: base(next, options, loggerFactory, encoder, configureOptions) | |||
{ | |||
if (Options.Notifications == null) | |||
{ | |||
Options.Notifications = new OAuthBearerAuthenticationNotifications(); |
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.
Can you revert this half too please?
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.
Done. I also reverted the same change for OIDC and added a check for the OAuth2 generic middleware.
…idators list by a single validator
This pull request fixes a few things that were not solved by @brentschmaltz's PR (#112).
Please note that it's still a WIP and that I'll probably add more commits.
/cc @HaoK @brentschmaltz