Yoast\WP\SEO\AI_Authorization\Application
Token_Manager::token_invalidate
Invalidates the access token.
The locally stored JWTs are always cleared, even when the remote invalidation fails — the remote exception still propagates to the caller, but no credentials are left behind.
Метод класса: Token_Manager{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$Token_Manager = new Token_Manager(); $Token_Manager->token_invalidate( $user_id ): void;
- $user_id(int) (обязательный)
- The user ID.
Код Token_Manager::token_invalidate() Token Manager::token invalidate Yoast 28.3
public function token_invalidate( int $user_id ): void {
try {
$access_jwt = $this->access_token_repository->get_token( $user_id );
} catch ( RuntimeException $e ) {
$access_jwt = '';
}
$request_headers = [
'Authorization' => "Bearer $access_jwt",
];
try {
// The endpoint takes no request body; the user is identified by the access token.
$this->request_handler->handle(
new Request(
'/token/invalidate',
[],
$request_headers,
),
);
} catch ( Unauthorized_Exception | Forbidden_Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch -- Reason: Ignored on purpose.
// If the credentials in our request were already invalid, our job is done and we continue to remove the tokens client-side.
} finally {
// Always clear the local tokens, even when the remote invalidation fails with an exception
// that propagates: leaving credentials behind would contradict the intent of invalidating.
$this->clear_tokens( $user_id );
}
}