Skip to content

Commit

Permalink
Merge pull request #60 from wp-graphql/revert-56-revert-55-feature/wp…
Browse files Browse the repository at this point in the history
…-graphql-v0.6.0-support

Revert "Revert "Adds WPGraphQL v0.6.0 support""
  • Loading branch information
jasonbahl authored Jan 21, 2020
2 parents d540fa3 + f1170be commit 2ebbc31
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 318 deletions.
6 changes: 4 additions & 2 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ public static function get_token_expiration() {
}

/**
* @param $user
* Retrieves validates user and retrieve signed token
*
* @param User|WP_User $user Owner of the token.
*
* @return null|string
*/
protected static function get_signed_token( \WP_User $user, $cap_check = true ) {
protected static function get_signed_token( $user, $cap_check = true ) {

/**
* Only allow the currently signed in user access to a JWT token
Expand Down
81 changes: 43 additions & 38 deletions src/Login.php
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'] ) );
},
]
);
}

}
Loading

0 comments on commit 2ebbc31

Please sign in to comment.