Skip to content

Commit

Permalink
Merge pull request #22 from alleyinteractive/feature/jwt-logged-in
Browse files Browse the repository at this point in the history
Ignore JWT authentication for the REST API if the user is already authenticated
  • Loading branch information
srtfisher committed Mar 20, 2024
2 parents b037f7b + 4c34858 commit a29840f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `wp-rest-guard` will be documented in this file.

## v1.3.1 - 2024-03-18

- Ignore JWT authentication for the REST API if the user is already authenticated.

## v1.3.0 - 2024-02-27

- Allow the claims to be added to a generated JWT via filter.
Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function should_prevent_anonymous_access( WP_REST_Server $server, WP_REST_Reques
return false;
}

if ( class_exists( JWT::class ) ) {
if ( class_exists( JWT::class ) && ! is_user_logged_in() ) {
/**
* Check if the anonymous request requires a JSON Web Token (JWT).
*
Expand Down
3 changes: 2 additions & 1 deletion tests/RestApiGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public function test_prevent_anonymous_access_settings() {
}

public function test_check_options_requests() {
$this->expectApplied( 'rest_api_guard_check_options_requests' )->times( 3 );
$this->assertNotAuthenticated();
$this->expectApplied( 'rest_api_guard_check_options_requests' )->times( 8 );

// Check the default settings.
update_option(
Expand Down

0 comments on commit a29840f

Please sign in to comment.