Skip to content

Commit b9d7374

Browse files
committed
Authenticate when passed a token
1 parent aeedfa6 commit b9d7374

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

inc/tokens/class-access-token.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ protected static function get_meta_prefix() {
1515
return static::META_PREFIX;
1616
}
1717

18+
/**
19+
* Get the ID for the user that the token represents.
20+
*
21+
* @return int
22+
*/
23+
public function get_user_id() {
24+
return (int) $this->value['user'];
25+
}
26+
27+
/**
28+
* Get the user that the token represents.
29+
*
30+
* @return WP_User|null
31+
*/
32+
public function get_user() {
33+
return get_user_by( 'id', $this->get_user_id() );
34+
}
35+
1836
/**
1937
* Get a token by ID.
2038
*

plugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function bootstrap() {
1717
load();
1818

1919
/** @todo Implement this :) */
20-
// add_filter( 'determine_current_user', __NAMESPACE__ . '\\attempt_authentication' );
20+
add_filter( 'determine_current_user', __NAMESPACE__ . '\\Authentication\\attempt_authentication', 11 );
2121
add_filter( 'oauth2.grant_types', __NAMESPACE__ . '\\register_grant_types', 0 );
2222
add_action( 'init', __NAMESPACE__ . '\\rest_oauth2_load_authorize_page' );
2323
add_action( 'admin_menu', array( __NAMESPACE__ . '\\admin\\Admin', 'register' ) );
@@ -26,6 +26,7 @@ function bootstrap() {
2626
function load() {
2727
require __DIR__ . '/inc/class-client.php';
2828
require __DIR__ . '/inc/class-scopes.php';
29+
require __DIR__ . '/inc/authentication/namespace.php';
2930
require __DIR__ . '/inc/endpoints/class-authorization.php';
3031
require __DIR__ . '/inc/tokens/namespace.php';
3132
require __DIR__ . '/inc/tokens/class-token.php';

0 commit comments

Comments
 (0)