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

Extract creation and storage of the access token into its own method. #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Extract creation and storage of the access token into its own method. #185

wants to merge 1 commit into from

Conversation

stephenharris
Copy link

This PR moves the part of the code responsible for instantiating a new access key and storing to a public static function.

This allows third-parties to create access tokens without duplicating the code, and acts as a counterpart to WP_REST_OAuth1::revoke_access_token().

Why? I've developed an add-on for the OAuth1 plug-in which allows you to create a single access token. A single access token is a 'manually' created access token tied to a user account. It's primary purpose is single-user applications, where effectively the end-user and consumer are the one and the same. In such instances, implementing the entire OAuth token acquisition dance unnecessarily complicates matters. It serves the same purpose as 'application passwords', but provides the security that application passwords lack (at least over non-HTTPS connections).

Introducing the WP_REST_OAuth1::create_access_token() function gives that add-on something to use rather than duplicating code.

@kosso
Copy link
Contributor

kosso commented Nov 27, 2016

Useful. But this seems like something more suited to a plugin, if at all possible.

@stephenharris
Copy link
Author

Its is. The PR was to abstract some code regarding token storage from the business logic of the REST API key-exchange endpoints to make it useful for said plugin.

Copy link
Member

@rmccue rmccue left a comment

Choose a reason for hiding this comment

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

Single-use sounds great; I've wanted to do something similar, but never had the time. Got a link to your plugin?

PR looks good, but indentation is off in a couple of spots here.

* handles the actual creation and storage of the access token.
*
* @param WP_Post $consumer
* @param int $user_id
Copy link
Member

Choose a reason for hiding this comment

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

Indentation is off in a couple of places here.

@stephenharris
Copy link
Author

Will update my PR later.

I've added the plug-in as gist here: https://gist.github.com/stephenharris/8584b6d6e0c0e996c125a34b01a962a7

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.

None yet

3 participants