Skip to content

Add WP API endpoint to generate tokens#28

Merged
danielbachhuber merged 26 commits into
danielbachhuber:masterfrom
gdespoulain:wp-api-endpoint
Aug 30, 2021
Merged

Add WP API endpoint to generate tokens#28
danielbachhuber merged 26 commits into
danielbachhuber:masterfrom
gdespoulain:wp-api-endpoint

Conversation

@gdespoulain

@gdespoulain gdespoulain commented Jul 9, 2021

Copy link
Copy Markdown
Contributor

Hi!

Here is a proposition for an API endpoint if you like :)

Changes:

  • Add a WP API endpoint /user/one-time-login/v1/token
  • Extract token generation in a function used by both API and CLI
  • Add unit tests for the token generation function
  • Update documentation (readme files) accordingly

Have fun!

@gdespoulain gdespoulain mentioned this pull request Jul 9, 2021

@danielbachhuber danielbachhuber left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Great start! Left some comments to be discussed.

Comment thread one-time-login.php Outdated
Comment thread one-time-login.php Outdated
Comment thread one-time-login.php
Comment thread one-time-login.php
@danielbachhuber

Copy link
Copy Markdown
Owner

@gdespoulain Are you ready for a final review here?

@gdespoulain

Copy link
Copy Markdown
Contributor Author

@danielbachhuber let's go, do you have something you still see as a blocker or are we good to go? :)

Comment thread one-time-login.php Outdated
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'one_time_login_api_request',
'args' => array(
'user' => array(),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is user a required argument? It seems nothing would happen if it's not provided:

image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, in the WP CLI command it seemed to be a required argument as well so I kept it that way

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ok. Can you add 'required' => true to the argument definition, and remove the isset( $parameters['user'] ) check in the callback?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When you don't set 'required' => false, the default is always true, that's why it's not there (it's not necessary).

Concerning the isset: I find it better to check the existence of a value before using it, as a principle, just to prevent ending up in a fatal error in the case something unexpected happens

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

When you don't set 'required' => false, the default is always true, that's why it's not there (it's not necessary).

Let's add it, just for the sake of clarity.

Concerning the isset: I find it better to check the existence of a value before using it, as a principle, just to prevent ending up in a fatal error in the case something unexpected happens

I think we'd want a fatal error in this case, to indicate something is broken (vs. an empty response which makes it less obvious that something is broken).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, done

@danielbachhuber

Copy link
Copy Markdown
Owner

@gdespoulain Just one last question, I think.

@danielbachhuber danielbachhuber added this to the 0.4.0 milestone Aug 30, 2021
@danielbachhuber danielbachhuber self-requested a review August 30, 2021 22:50
@danielbachhuber danielbachhuber merged commit f809c8b into danielbachhuber:master Aug 30, 2021
@danielbachhuber

Copy link
Copy Markdown
Owner

Thanks for your work on this, @gdespoulain ! I've just tagged the v0.4.0 release.

@gdespoulain

Copy link
Copy Markdown
Contributor Author

@danielbachhuber Thank you too! :) Nice to have worked on this plugin! :)

@gdespoulain gdespoulain deleted the wp-api-endpoint branch August 31, 2021 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants