Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Link to issue w comment
  • Loading branch information
pcraciunoiu authored Jul 14, 2021
commit d81b24d66461f7f58799f94f90ac5b1001b1d4f8
6 changes: 6 additions & 0 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ protected static function get_signed_token( $user, $cap_check = true ) {
* Only allow the currently signed in user access to a JWT token
*/
if ( true === $cap_check && get_current_user_id() !== $user->ID || 0 === $user->ID ) {
// See https://github.com/wp-graphql/wp-graphql-jwt-authentication/issues/111
self::set_status(400);
return new \WP_Error( 'graphql-jwt-no-permissions', __( 'Only the user requesting a token can get a token issued for them', 'wp-graphql-jwt-authentication' ) );
}
Expand Down Expand Up @@ -455,6 +456,7 @@ public static function revoke_user_secret( $user_id ) {
return true;

} else {
// See https://github.com/wp-graphql/wp-graphql-jwt-authentication/issues/111
self::set_status(401);
return new \WP_Error( 'graphql-jwt-auth-cannot-revoke-secret', __( 'The JWT Auth Secret cannot be revoked for this user', 'wp-graphql-jwt-authentication' ) );

Expand Down Expand Up @@ -495,6 +497,7 @@ public static function unrevoke_user_secret( int $user_id ) {
return true;

} else {
// See https://github.com/wp-graphql/wp-graphql-jwt-authentication/issues/111
self::set_status(401);
return new \WP_Error( 'graphql-jwt-auth-cannot-unrevoke-secret', __( 'The JWT Auth Secret cannot be unrevoked for this user', 'wp-graphql-jwt-authentication' ) );

Expand Down Expand Up @@ -556,6 +559,7 @@ public static function validate_token( $token = null, $refresh = false ) {
* If there's no secret key, throw an error as there needs to be a secret key for Auth to work properly
*/
if ( ! self::get_secret_key() ) {
// See https://github.com/wp-graphql/wp-graphql-jwt-authentication/issues/111
self::set_status( 403 );
return new \WP_Error( 'invalid-secret-key', __( 'JWT is not configured properly', 'wp-graphql-jwt-authentication' ) );
}
Expand Down Expand Up @@ -596,6 +600,7 @@ public static function validate_token( $token = null, $refresh = false ) {
* So far so good, validate the user id in the token
*/
if ( ! isset( $token->data->user->id ) ) {
// See https://github.com/wp-graphql/wp-graphql-jwt-authentication/issues/111
self::set_status(401);
return new \WP_Error( 'invalid-jwt', __( 'User ID not found in the token', 'wp-graphql-jwt-authentication' ) );
}
Expand All @@ -606,6 +611,7 @@ public static function validate_token( $token = null, $refresh = false ) {
if ( isset( $token->data->user->user_secret ) ) {

if ( Auth::is_jwt_secret_revoked( $token->data->user->id ) ) {
// See https://github.com/wp-graphql/wp-graphql-jwt-authentication/issues/111
self::set_status(401);
return new \WP_Error( 'invalid-jwt', __( 'The User Secret does not match or has been revoked for this user', 'wp-graphql-jwt-authentication' ) );
}
Expand Down