Skip to content

Commit 5a7d9a9

Browse files
authored
Merge pull request #170 from wp-graphql/release/v0.6.0
Release/v0.6.0
2 parents 9e8678d + 926c16a commit 5a7d9a9

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/Auth.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,19 @@ public static function is_refresh_token() {
370370
*/
371371
protected static function authenticate_user( $username, $password ) {
372372

373-
/**
374-
* Try to authenticate the user with the passed credentials
375-
*/
376-
$user = wp_authenticate( sanitize_user( $username ), trim( $password ) );
373+
if ( defined( 'GRAPHQL_JWT_AUTH_SET_COOKIES' ) && ! empty( GRAPHQL_JWT_AUTH_SET_COOKIES ) && GRAPHQL_JWT_AUTH_SET_COOKIES ) {
374+
$credentials = [
375+
'user_login' => sanitize_user( $username ),
376+
'user_password' => trim( $password ),
377+
'remember' => false,
378+
];
379+
380+
// Try to authenticate the user with the passed credentials, log him in and set cookies
381+
$user = wp_signon( $credentials, true );
382+
} else {
383+
// Try to authenticate the user with the passed credentials
384+
$user = wp_authenticate( sanitize_user( $username ), trim( $password ) );
385+
}
377386

378387
/**
379388
* If the authentication fails return a error

src/ManageTokens.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,7 @@ public static function add_auth_headers_to_rest_response( $response ) {
342342
*
343343
* Might need a patch to core to allow for individual filtering.
344344
*/
345-
$response->set_headers(
346-
[ 'Access-Control-Expose-Headers' => 'X-WP-Total, X-WP-TotalPages, X-JWT-Refresh' ]
347-
);
345+
$response->header( 'Access-Control-Expose-Headers', 'X-WP-Total, X-WP-TotalPages, X-JWT-Refresh', true );
348346

349347
$refresh_token = null;
350348

@@ -357,7 +355,7 @@ public static function add_auth_headers_to_rest_response( $response ) {
357355
}
358356

359357
if ( $refresh_token ) {
360-
$response->set_headers( [ 'X-JWT-Refresh' => $refresh_token ] );
358+
$response->header( 'X-JWT-Refresh', $refresh_token, true );
361359
}
362360

363361
return $response;

wp-graphql-jwt-authentication.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Author URI: https://www.wpgraphql.com
88
* Text Domain: wp-graphql-jwt-authentication-jwt-authentication
99
* Domain Path: /languages
10-
* Version: 0.5.2
10+
* Version: 0.6.0
1111
* Requires at least: 4.7.0
1212
* Tested up to: 4.8.3
1313
* Requires PHP: 5.5
@@ -113,7 +113,7 @@ public function __wakeup() {
113113
private function setup_constants() {
114114
// Plugin version.
115115
if ( ! defined( 'WPGRAPHQL_JWT_AUTHENTICATION_VERSION' ) ) {
116-
define( 'WPGRAPHQL_JWT_AUTHENTICATION_VERSION', '0.5.2' );
116+
define( 'WPGRAPHQL_JWT_AUTHENTICATION_VERSION', '0.6.0' );
117117
}
118118

119119
// Plugin Folder Path.

0 commit comments

Comments
 (0)