-
Notifications
You must be signed in to change notification settings - Fork 598
Replace configure method on TwitterOptions and OpenIdConnectOptions with CookieBuilder #1284
Conversation
@natemcmaster, |
}; | ||
|
||
Options.ConfigureNonceCookie?.Invoke(Context, cookieOptions); | ||
cookieOptions.Path = OriginalPathBase + Options.CallbackPath; |
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.
Maybe just do this instead? cookieOptions.Path = cookieOptions.Path ?? OriginalPathBase + Options.CallbackPath;
There's also a subtle bug here, since even if Path == null, the Builder could set the cookie.Path, which would get blasted away
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.
Yes, that's why this deliberately checks if (Options.NonceCookie.Path == null)
first.
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.
Yeah so what if they have CustomCookieBuilder which sets cookieOptions.Path = "/mypath" in Build(), this code will still stomp on the path. The check should be checking the real cookieOptions.Path, not the builder property
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.
Hmm. This is problematic. The default ctor for CookieOptions always sets Path to "/". If someone implements a custom cookie builder, it will be hard for us to detect if they indend to overwrite the default value or not.
var builder = new CookieBuilder();
// builder.Path= null
var options = builder.Build(context)
// options.Path= "/"
// builder.Path== null means we can assume the user does not indent to change
// the default path, therefore we set it to OriginalPathBase + Options.CallbackPath
var builder = new MyCustomCookieBuilder();
// builder.Path= null
var options = builder.Build(context)
// options.Path= "/mypath"
// builder.Path== null means ????
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.
Just check for options.Path == "/" and builder.Path== null?
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.
We are talking about Path not name right?
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 can just check for options.Path == "/" since we can't really assume anything based on the property alone.
if (cookieOptions.Path == "/") {
cookieOptions.Path = OriginalPathBase + Options.CallbackPath;
}
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 figured out a way to do that. I override the build method to detect the value of Path before. Should allow user to override.
Expires = Clock.UtcNow.Add(Options.ProtocolValidator.NonceLifetime) | ||
}; | ||
var cookieOptions = Options.NonceCookie.Build(Context); | ||
cookieOptions.Expires = Clock.UtcNow.Add(Options.ProtocolValidator.NonceLifetime); |
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.
This isn't honoring the Expiration from CookieBuilder. Only set it if not null?
Any way to resolve Options.ProtocolValidator.NonceLifetime in the builder? Then you could incorporate it in a way that could be overridden.
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.
Yup, just add a Property in a OpenIdConnectCookieBuilder for it
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.
Updated
@@ -50,7 +49,8 @@ public TwitterHandler(IOptionsSnapshot<TwitterOptions> options, ILoggerFactory l | |||
{ | |||
AuthenticationProperties properties = null; | |||
var query = Request.Query; | |||
var protectedRequestToken = Request.Cookies[StateCookie]; | |||
var cookieName = Options.StateCookie.Name ?? StateCookieName; |
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.
Yeah, this gets simpler if we prevent Name from being null.
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.
Updated.
Add support for the correlation cookie, or file a followup bug since this isn't currently configurable.
|
Should just make the change in this PR for correlation cookie |
2cbf29b
to
0a740b2
Compare
Rebased and added the correlation cookie change to this PR. |
var path = Path; | ||
if (path == null) | ||
{ | ||
var originalPathBase = context.Features.Get<IAuthenticationFeature>()?.OriginalPathBase ?? context.Request.PathBase; |
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.
Should we consider having the handlers set a OriginalPathBase property on the CookieBuilder instead of having the builder pull it from the context?
var path = Path; | ||
if (path == null) | ||
{ | ||
var originalPathBase = context.Features.Get<IAuthenticationFeature>()?.OriginalPathBase ?? context.Request.PathBase; |
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.
Commenting again in the right version: Should we make this a property on RequestPathBaseCookieBuilder that the handlers set instead of making the builder pull it out?
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.
Possibly racy. The builder is shared across multiple contexts.
0403f05
to
d7cc4bb
Compare
🔔 |
{ | ||
Logger.CorrelationPropertyNotFound(CorrelationPrefix); | ||
Logger.CorrelationPropertyNotFound(RemoteAuthenticationOptions.CorrelationPrefix); |
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.
Shouldn't this be something like Options.CorrelationCookie.Name 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.
Yup. Updated.
…Connect options with CookieBuilder
a565a24
to
968237d
Compare
|
||
Response.Cookies.Delete(StateCookie, cookieOptions); | ||
Response.Cookies.Delete(Options.StateCookie.Name, cookieOptions); |
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'm trying to think if a user would Build their options any differently if they knew they were building a delete cookie.
Addresses aspnet/HttpAbstractions#853.
Uses the new CookieBuilder API added here: aspnet/HttpAbstractions#882
Part 1- look for a separate PR to remove duplication from CookieAuthenticationOptions.