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

Improve WP_Auth0_Options #418

Merged
merged 2 commits into from
Mar 28, 2018
Merged

Improve WP_Auth0_Options #418

merged 2 commits into from
Mar 28, 2018

Conversation

joshcanhelp
Copy link
Contributor

Adding get_lock_connections and add_lock_connection for working with
separated options field. reordering option defaults, remove comments,
add docblocks

Adding get_lock_connections and add_lock_connection for working with
separated options field. reordering option defaults, remove comments,
add docblocks
@joshcanhelp joshcanhelp added this to the v3-Next milestone Mar 27, 2018
@joshcanhelp joshcanhelp self-assigned this Mar 27, 2018
public function get_client_signing_algorithm() {
$client_signing_algorithm = $this->get('client_signing_algorithm', WP_Auth0_Api_Client::DEFAULT_CLIENT_ALG);
return $client_signing_algorithm;
return $this->get( 'client_signing_algorithm', WP_Auth0_Api_Client::DEFAULT_CLIENT_ALG );
Copy link
Contributor

Choose a reason for hiding this comment

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

is this like this get(key, valueIfMissing)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

@@ -129,92 +134,124 @@ public function get_logout_url() {
return add_query_arg( 'action', 'logout', site_url( 'wp-login.php', 'login' ) );
}

/**
* Get as a string-separated string and parse to array
Copy link
Contributor

Choose a reason for hiding this comment

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

No. That's what the method does internally. What devs should care is "obtain the connections as an array of strings".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"string-separated string" 😆

* @return array
*/
public function get_lock_connections() {
$connections = $this->get( 'lock_connections' );
Copy link
Contributor

Choose a reason for hiding this comment

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

why is the lock_connections a "string,of,connections"? It seems you are always manipulating arrays. Can it be defined as an array to avoid all this coming and going from one structure to the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The field in on the settings page is just a text field so comma-separated (or line break or pipe or whatever) is about the best we can do without a UI to force multiple, separate values. This is basically to handle user input

public function get_lock_connections() {
$connections = $this->get( 'lock_connections' );
$connections = empty( $connections ) ? array() : explode( ',', $connections );
return array_map( 'trim', $connections );
Copy link
Contributor

Choose a reason for hiding this comment

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

is the trim needed because it's a user input or because you don't trust the source? (i don't know where it comes from)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

User input

'amplificator_title' => '',
'amplificator_subtitle' => '',
'connections' => array(),
'auth0js-cdn' => '//cdn.auth0.com/js/auth0/9.1/auth0.min.js',
Copy link
Contributor

Choose a reason for hiding this comment

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

you are using https, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some folks are, some are not ... though this URL will always be https so I guess that could be explicit here? This is just a reordering, FYI

Copy link
Contributor

Choose a reason for hiding this comment

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

it's hosted by auth0 so I don't see a reason why they shouldn't be using https. They don't need to setup anything on their side. It's not like a custom domain where the certificate needs to be handled by your or something like that.. I'd enforce https on all auth0 urls. Double check with luis, but i think that's the right choice.

Copy link
Contributor

Choose a reason for hiding this comment

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

this should be always https

@@ -556,8 +556,6 @@ public function connections_validation( $old_options, $input ) {

if ($input['passwordless_enabled'] && $input['passwordless_enabled'] != $old_options['passwordless_enabled']) {

// $check_if_enabled = explode(',', $input['lock_connections']);
Copy link
Contributor

Choose a reason for hiding this comment

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

what happened to all these comments that are now removed? was it implemented somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They've been commented for a while

Copy link
Contributor

Choose a reason for hiding this comment

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

but is it something you want to do someday? are you tracking it somewhere else or are they just gone for good? 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what it's for, it's obviously not doing anything, and it's related to the settings I'm working with so 👋

:)

*
* @param string $add_conn - connection name to add
*/
public function add_lock_connection( $add_conn ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rename this parameter to "connection" or "conn" since the method name already describes what you are doing with it.

$connections = $this->get_lock_connections();

// Add if it doesn't exist already
if ( ! array_key_exists( $add_conn, $connections ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a suggestion:
It could be more performant if you FIRST check that the string from $this->get( 'lock_connections' ); "contains" the trimmed $add_conn parameter.

  • If it DOES contain it, return (skip). This way, you avoid converting it to an array in the first place.
  • if not, then you can call the get_lock_connections() method that prepares the array for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can't really do that can you? What if I want to add the connection google-oauth so I search for the string google in twitter,facebook,google-oauth2 and it's there so I bail out?

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.

Thanks 🎉

@joshcanhelp joshcanhelp merged commit 85d9476 into dev Mar 28, 2018
@joshcanhelp joshcanhelp deleted the fix-options-class branch March 28, 2018 20:57
@joshcanhelp joshcanhelp mentioned this pull request Jun 5, 2018
@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.

3 participants