Skip to content

Commit ce83515

Browse files
committed
Add method to revoke tokens
1 parent 6e0e8a0 commit ce83515

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

inc/tokens/class-access-token.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ public function get_client() {
2727
return Client::get_by_id( $this->value['client'] );
2828
}
2929

30+
/**
31+
* Revoke the token.
32+
*
33+
* @internal This may return other error codes in the future, as we may
34+
* need to also revoke refresh tokens.
35+
* @return bool|WP_Error True if succeeded, error otherwise.
36+
*/
37+
public function revoke() {
38+
$success = delete_user_meta( $this->get_user_id(), $this->get_meta_key() );
39+
if ( ! $success ) {
40+
return new WP_Error(
41+
'oauth2.tokens.access_token.revoke.could_not_revoke',
42+
__( 'Could not revoke the token.', 'oauth2' )
43+
);
44+
}
45+
46+
return true;
47+
}
48+
3049
/**
3150
* Get a token by ID.
3251
*

0 commit comments

Comments
 (0)