Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Adds WPGraphQL v0.6.0 support"" #60

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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