Skip to content

Commit 2ebbc31

Browse files
authored
Merge pull request #60 from wp-graphql/revert-56-revert-55-feature/wp-graphql-v0.6.0-support
Revert "Revert "Adds WPGraphQL v0.6.0 support""
2 parents d540fa3 + f1170be commit 2ebbc31

File tree

5 files changed

+243
-318
lines changed

5 files changed

+243
-318
lines changed

src/Auth.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,13 @@ public static function get_token_expiration() {
121121
}
122122

123123
/**
124-
* @param $user
124+
* Retrieves validates user and retrieve signed token
125+
*
126+
* @param User|WP_User $user Owner of the token.
125127
*
126128
* @return null|string
127129
*/
128-
protected static function get_signed_token( \WP_User $user, $cap_check = true ) {
130+
protected static function get_signed_token( $user, $cap_check = true ) {
129131

130132
/**
131133
* Only allow the currently signed in user access to a JWT token

src/Login.php

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,57 @@
11
<?php
2+
/**
3+
* Register the login mutation to the WPGraphQL Schema
4+
*
5+
* @package WPGraphQL\JWT_Authentication
6+
* @since 0.0.1
7+
*/
8+
29
namespace WPGraphQL\JWT_Authentication;
310

411
use GraphQL\Type\Definition\ResolveInfo;
512
use WPGraphQL\AppContext;
613

14+
/**
15+
* Class - Login
16+
*/
717
class Login {
8-
918
/**
10-
* Register the login mutation to the WPGraphQL Schema
19+
* Register the mutation.
1120
*/
1221
public static function register_mutation() {
13-
14-
register_graphql_mutation( 'login', [
15-
'description' => __( 'Login a user. Request for an authToken and User details in response', 'wp-graphql-jwt-authentication' ),
16-
'inputFields' => [
17-
'username' => [
18-
'type' => [ 'non_null' => 'String' ],
19-
'description' => __( 'The username used for login. Typically a unique or email address depending on specific configuration', 'wp-graphql-jwt-authentication' ),
20-
],
21-
'password' => [
22-
'type' => [ 'non_null' => 'String' ],
23-
'description' => __( 'The plain-text password for the user logging in.', 'wp-graphql-jwt-authentication' ),
24-
],
25-
],
26-
'outputFields' => [
27-
'authToken' => [
28-
'type' => 'String',
29-
'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-jwt-authentication' ),
22+
register_graphql_mutation(
23+
'login',
24+
[
25+
'description' => __( 'Login a user. Request for an authToken and User details in response', 'wp-graphql-jwt-authentication' ),
26+
'inputFields' => [
27+
'username' => [
28+
'type' => [ 'non_null' => 'String' ],
29+
'description' => __( 'The username used for login. Typically a unique or email address depending on specific configuration', 'wp-graphql-jwt-authentication' ),
30+
],
31+
'password' => [
32+
'type' => [ 'non_null' => 'String' ],
33+
'description' => __( 'The plain-text password for the user logging in.', 'wp-graphql-jwt-authentication' ),
34+
],
3035
],
31-
'refreshToken' => [
32-
'type' => 'String',
33-
'description' => __( 'A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.', 'wp-graphql-jwt-authentication' ),
36+
'outputFields' => [
37+
'authToken' => [
38+
'type' => 'String',
39+
'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-jwt-authentication' ),
40+
],
41+
'refreshToken' => [
42+
'type' => 'String',
43+
'description' => __( 'A JWT token that can be used in future requests to get a refreshed jwtAuthToken. If the refresh token used in a request is revoked or otherwise invalid, a valid Auth token will NOT be issued in the response headers.', 'wp-graphql-jwt-authentication' ),
44+
],
45+
'user' => [
46+
'type' => 'User',
47+
'description' => __( 'The user that was logged in', 'wp-graphql-jwt-authentication' ),
48+
],
3449
],
35-
'user' => [
36-
'type' => 'User',
37-
'description' => __( 'The user that was logged in', 'wp-graphql-jwt-authentication' ),
38-
],
39-
],
40-
'mutateAndGetPayload' => function( $input, AppContext $context, ResolveInfo $info ) {
41-
42-
/**
43-
* Login the user in and get an authToken and user in response
44-
*/
45-
return Auth::login_and_get_token( sanitize_user( $input['username'] ), trim( $input['password'] ) );
46-
47-
},
48-
]);
49-
50+
'mutateAndGetPayload' => function( $input, AppContext $context, ResolveInfo $info ) {
51+
// Login the user in and get an authToken and user in response.
52+
return Auth::login_and_get_token( sanitize_user( $input['username'] ), trim( $input['password'] ) );
53+
},
54+
]
55+
);
5056
}
51-
5257
}

0 commit comments

Comments
 (0)