-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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""
- Loading branch information
Showing
5 changed files
with
243 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,57 @@ | ||
<?php | ||
/** | ||
* Register the login mutation to the WPGraphQL Schema | ||
* | ||
* @package WPGraphQL\JWT_Authentication | ||
* @since 0.0.1 | ||
*/ | ||
|
||
namespace WPGraphQL\JWT_Authentication; | ||
|
||
use GraphQL\Type\Definition\ResolveInfo; | ||
use WPGraphQL\AppContext; | ||
|
||
/** | ||
* Class - Login | ||
*/ | ||
class Login { | ||
|
||
/** | ||
* Register the login mutation to the WPGraphQL Schema | ||
* Register the mutation. | ||
*/ | ||
public static function register_mutation() { | ||
|
||
register_graphql_mutation( 'login', [ | ||
'description' => __( 'Login a user. Request for an authToken and User details in response', 'wp-graphql-jwt-authentication' ), | ||
'inputFields' => [ | ||
'username' => [ | ||
'type' => [ 'non_null' => 'String' ], | ||
'description' => __( 'The username used for login. Typically a unique or email address depending on specific configuration', 'wp-graphql-jwt-authentication' ), | ||
], | ||
'password' => [ | ||
'type' => [ 'non_null' => 'String' ], | ||
'description' => __( 'The plain-text password for the user logging in.', 'wp-graphql-jwt-authentication' ), | ||
], | ||
], | ||
'outputFields' => [ | ||
'authToken' => [ | ||
'type' => 'String', | ||
'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-jwt-authentication' ), | ||
register_graphql_mutation( | ||
'login', | ||
[ | ||
'description' => __( 'Login a user. Request for an authToken and User details in response', 'wp-graphql-jwt-authentication' ), | ||
'inputFields' => [ | ||
'username' => [ | ||
'type' => [ 'non_null' => 'String' ], | ||
'description' => __( 'The username used for login. Typically a unique or email address depending on specific configuration', 'wp-graphql-jwt-authentication' ), | ||
], | ||
'password' => [ | ||
'type' => [ 'non_null' => 'String' ], | ||
'description' => __( 'The plain-text password for the user logging in.', 'wp-graphql-jwt-authentication' ), | ||
], | ||
], | ||
'refreshToken' => [ | ||
'type' => 'String', | ||
'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' ), | ||
'outputFields' => [ | ||
'authToken' => [ | ||
'type' => 'String', | ||
'description' => __( 'JWT Token that can be used in future requests for Authentication', 'wp-graphql-jwt-authentication' ), | ||
], | ||
'refreshToken' => [ | ||
'type' => 'String', | ||
'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' ), | ||
], | ||
'user' => [ | ||
'type' => 'User', | ||
'description' => __( 'The user that was logged in', 'wp-graphql-jwt-authentication' ), | ||
], | ||
], | ||
'user' => [ | ||
'type' => 'User', | ||
'description' => __( 'The user that was logged in', 'wp-graphql-jwt-authentication' ), | ||
], | ||
], | ||
'mutateAndGetPayload' => function( $input, AppContext $context, ResolveInfo $info ) { | ||
|
||
/** | ||
* Login the user in and get an authToken and user in response | ||
*/ | ||
return Auth::login_and_get_token( sanitize_user( $input['username'] ), trim( $input['password'] ) ); | ||
|
||
}, | ||
]); | ||
|
||
'mutateAndGetPayload' => function( $input, AppContext $context, ResolveInfo $info ) { | ||
// Login the user in and get an authToken and user in response. | ||
return Auth::login_and_get_token( sanitize_user( $input['username'] ), trim( $input['password'] ) ); | ||
}, | ||
] | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.