Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a filter for nonce and state cookie names #495

Merged
merged 1 commit into from
Jun 28, 2018

Conversation

joshcanhelp
Copy link
Contributor

@joshcanhelp joshcanhelp commented Jun 28, 2018

  • Change the protected get_storage_cookie_name() to public + static
  • Add a auth0_state_cookie_name and auth0_none_cookie_name filter to the two affected methods
  • Change direct calling of the cookie name constants to the static method

Sample usage:

/**
 * Prefix state and nonce cookie names. 
 * 
 * @param string $cookie_name - Cookie name to modify.
 * 
 * @return string
 */
function auth0_theme_hook_prefix_cookie_name( $cookie_name ) {
	return 'STYXKEY_' . $cookie_name;
}
 add_filter( 'auth0_state_cookie_name', 'auth0_theme_hook_prefix_cookie_name' );
 add_filter( 'auth0_nonce_cookie_name', 'auth0_theme_hook_prefix_cookie_name' );

Passes all functional tests.

Closes #494

@joshcanhelp joshcanhelp added this to the v3-Next milestone Jun 28, 2018
Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

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

what if instead of having setters for each cookie name you add a method that affects ALL the cookies' names and allows the user to set the name prefix? You'd use it like this: self::get_cookie_prefix() + static::NONCE_COOKIE_NAME

This way 1 change fixes all future errors. Unless of course, you consider the state and nonce the only ones that could fall into this issue.

// Have a cookie, don't want to generate a new one.
$this->unique = $_COOKIE[ static::NONCE_COOKIE_NAME ];
$this->unique = $_COOKIE[ self::get_storage_cookie_name() ];
Copy link
Contributor

Choose a reason for hiding this comment

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

what about self::get_cookie_prefix() + static::NONCE_COOKIE_NAME? Same for the remaining calls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to exert that kind of control, name is irrelevant.

@joshcanhelp
Copy link
Contributor Author

@lbalmaceda - I'd rather the developer have full control over the name.

@joshcanhelp
Copy link
Contributor Author

@lbalmaceda - Added a sample usage to prefix all cookie names.

@lbalmaceda
Copy link
Contributor

Ah it's easier than I thought. OK!

Copy link
Contributor

@lbalmaceda lbalmaceda left a comment

Choose a reason for hiding this comment

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

🍇

@joshcanhelp joshcanhelp merged commit 24ef791 into dev Jun 28, 2018
@joshcanhelp joshcanhelp deleted the add-nonce-cookie-name-filter branch June 28, 2018 18:33
@galengidman
Copy link

Thank you, thank you, thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2022
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.

None yet

3 participants