From 97e5556e56650fc7dcef0b2b66596e838f5b2e02 Mon Sep 17 00:00:00 2001 From: henrikwirth Date: Sat, 7 Mar 2020 18:18:30 +0100 Subject: [PATCH 1/7] Adds Option to define if a cookie should be set on login. --- src/Auth.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index ec0ea38..18d673c 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -355,10 +355,23 @@ public static function is_refresh_token() { */ protected static function authenticate_user( $username, $password ) { - /** - * Try to authenticate the user with the passed credentials - */ - $user = wp_authenticate( sanitize_user( $username ), trim( $password ) ); + if (defined( 'GRAPHQL_JWT_AUTH_SET_COOKIES' ) && ! empty( GRAPHQL_JWT_AUTH_SET_COOKIES ) && GRAPHQL_JWT_AUTH_SET_COOKIES) { + $credentials = [ + 'user_login' => sanitize_user( $username ), + 'user_password' => trim( $password ), + 'remember' => false, + ]; + + /** + * Try to authenticate the user with the passed credentials, log him in and set cookies + */ + $user = wp_signon( $credentials, true ); + } else { + /** + * Try to authenticate the user with the passed credentials + */ + $user = wp_authenticate( sanitize_user( $username ), trim( $password ) ); + } /** * If the authentication fails return a error From 1277d606ef32513a50ae06d0500634d8cf0462c5 Mon Sep 17 00:00:00 2001 From: Henrik Wirth Date: Tue, 10 Mar 2020 13:19:36 +0100 Subject: [PATCH 2/7] PHPDoc: correct inline comments. Co-Authored-By: Renato Alves --- src/Auth.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index 18d673c..f127b91 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -367,9 +367,7 @@ protected static function authenticate_user( $username, $password ) { */ $user = wp_signon( $credentials, true ); } else { - /** - * Try to authenticate the user with the passed credentials - */ + // Try to authenticate the user with the passed credentials $user = wp_authenticate( sanitize_user( $username ), trim( $password ) ); } From 2cecbbefaff7e605193bdfcd292d4afb35aa2b39 Mon Sep 17 00:00:00 2001 From: Henrik Wirth Date: Tue, 10 Mar 2020 13:19:42 +0100 Subject: [PATCH 3/7] PHPDoc: correct inline comments. Co-Authored-By: Renato Alves --- src/Auth.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index f127b91..e0e3d78 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -362,9 +362,7 @@ protected static function authenticate_user( $username, $password ) { 'remember' => false, ]; - /** - * Try to authenticate the user with the passed credentials, log him in and set cookies - */ + // Try to authenticate the user with the passed credentials, log him in and set cookies $user = wp_signon( $credentials, true ); } else { // Try to authenticate the user with the passed credentials From 23ad012d7659ac972cccdf2a69299ed172140cc0 Mon Sep 17 00:00:00 2001 From: Timothy Date: Wed, 4 Nov 2020 08:47:05 -0500 Subject: [PATCH 4/7] fix(response headers): replace header instead of setting them all updated to call the 'header' instead of 'set_headers' method when writing response headers to avoid overwriting all the headers such as X-WP-Total and X-WP-TotalPages which are necessary for different plugins and pieces of Wordpress to work properly --- src/ManageTokens.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ManageTokens.php b/src/ManageTokens.php index b4d893b..9616bd1 100644 --- a/src/ManageTokens.php +++ b/src/ManageTokens.php @@ -342,9 +342,7 @@ public static function add_auth_headers_to_rest_response( $response ) { * * Might need a patch to core to allow for individual filtering. */ - $response->set_headers( - [ 'Access-Control-Expose-Headers' => 'X-WP-Total, X-WP-TotalPages, X-JWT-Refresh' ] - ); + $response->header( 'Access-Control-Expose-Headers', 'X-WP-Total, X-WP-TotalPages, X-JWT-Refresh', true ); $refresh_token = null; @@ -357,7 +355,7 @@ public static function add_auth_headers_to_rest_response( $response ) { } if ( $refresh_token ) { - $response->set_headers( [ 'X-JWT-Refresh' => $refresh_token ] ); + $response->header( 'X-JWT-Refresh', $refresh_token, true ); } return $response; From e3692a9f3d975c46967fca714044891154f396fb Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Tue, 25 Oct 2022 08:34:39 -0600 Subject: [PATCH 5/7] Update src/Auth.php --- src/Auth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Auth.php b/src/Auth.php index 75f048f..c3d853a 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -353,7 +353,7 @@ public static function is_refresh_token() { */ protected static function authenticate_user( $username, $password ) { - if (defined( 'GRAPHQL_JWT_AUTH_SET_COOKIES' ) && ! empty( GRAPHQL_JWT_AUTH_SET_COOKIES ) && GRAPHQL_JWT_AUTH_SET_COOKIES) { + if ( defined( 'GRAPHQL_JWT_AUTH_SET_COOKIES' ) && ! empty( GRAPHQL_JWT_AUTH_SET_COOKIES ) && GRAPHQL_JWT_AUTH_SET_COOKIES ) { $credentials = [ 'user_login' => sanitize_user( $username ), 'user_password' => trim( $password ), From 0a288079a0a0e939ae42f795815d7cb8c01397e9 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Tue, 25 Oct 2022 08:39:01 -0600 Subject: [PATCH 6/7] - update version for release --- wp-graphql-jwt-authentication.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-graphql-jwt-authentication.php b/wp-graphql-jwt-authentication.php index 0e27c6c..31334e4 100644 --- a/wp-graphql-jwt-authentication.php +++ b/wp-graphql-jwt-authentication.php @@ -7,7 +7,7 @@ * Author URI: https://www.wpgraphql.com * Text Domain: wp-graphql-jwt-authentication-jwt-authentication * Domain Path: /languages - * Version: 0.5.2 + * Version: 0.5.3 * Requires at least: 4.7.0 * Tested up to: 4.8.3 * Requires PHP: 5.5 @@ -113,7 +113,7 @@ public function __wakeup() { private function setup_constants() { // Plugin version. if ( ! defined( 'WPGRAPHQL_JWT_AUTHENTICATION_VERSION' ) ) { - define( 'WPGRAPHQL_JWT_AUTHENTICATION_VERSION', '0.5.2' ); + define( 'WPGRAPHQL_JWT_AUTHENTICATION_VERSION', '0.5.3' ); } // Plugin Folder Path. From 926c16ae562b858c38d9b01e1a33951f7428a248 Mon Sep 17 00:00:00 2001 From: Jason Bahl Date: Tue, 25 Oct 2022 08:46:46 -0600 Subject: [PATCH 7/7] - update version for release --- wp-graphql-jwt-authentication.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-graphql-jwt-authentication.php b/wp-graphql-jwt-authentication.php index 31334e4..5946bba 100644 --- a/wp-graphql-jwt-authentication.php +++ b/wp-graphql-jwt-authentication.php @@ -7,7 +7,7 @@ * Author URI: https://www.wpgraphql.com * Text Domain: wp-graphql-jwt-authentication-jwt-authentication * Domain Path: /languages - * Version: 0.5.3 + * Version: 0.6.0 * Requires at least: 4.7.0 * Tested up to: 4.8.3 * Requires PHP: 5.5 @@ -113,7 +113,7 @@ public function __wakeup() { private function setup_constants() { // Plugin version. if ( ! defined( 'WPGRAPHQL_JWT_AUTHENTICATION_VERSION' ) ) { - define( 'WPGRAPHQL_JWT_AUTHENTICATION_VERSION', '0.5.3' ); + define( 'WPGRAPHQL_JWT_AUTHENTICATION_VERSION', '0.6.0' ); } // Plugin Folder Path.