Skip to content

Commit 3584291

Browse files
authored
Merge pull request #78 from wp-graphql/docs/add-all-mutations
Docs/add all mutations
2 parents 26f2c0c + 960339f commit 3584291

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

README.md

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ This plugin was initially based off the `wp-api-jwt-auth` plugin by Enrique Chav
1414

1515
## Install, Activate & Setup
1616

17-
You can install and activate the plugin like any WordPress plugin. Download the .zip from Github and add to your plugins directory, then activate.
17+
You can install and activate the plugin like any WordPress plugin. Download the .zip from Github and add to your plugins directory, then activate.
1818

19-
JWT uses a Secret defined on the server to validate the signing of tokens.
19+
JWT uses a Secret defined on the server to validate the signing of tokens.
2020

2121
It's recommended that you use something like the WordPress Salt generator (https://api.wordpress.org/secret-key/1.1/salt/) to generate a Secret.
2222

@@ -25,7 +25,7 @@ You can define a Secret like so:
2525
define( 'GRAPHQL_JWT_AUTH_SECRET_KEY', 'your-secret-token' );
2626
```
2727

28-
Or you can use the filter `graphql_jwt_auth_secret_key` to set a Secret like so:
28+
Or you can use the filter `graphql_jwt_auth_secret_key` to set a Secret like so:
2929

3030
```
3131
add_filter( 'graphql_jwt_auth_secret_key', function() {
@@ -51,15 +51,19 @@ For NGINX, this may work: https://serverfault.com/questions/511206/nginx-forward
5151

5252
## How the plugin Works
5353

54-
This plugin adds a new `login` mutation to the WPGraphQL Schema.
54+
### Login User
5555

56-
This can be used like so:
56+
This plugin adds a new `login` mutation to the WPGraphQL Schema.
5757

58-
```
58+
This can be used like so:
59+
60+
**Input-Type:** `LoginUserInput!`
61+
62+
```graphql
5963
mutation LoginUser {
6064
login( input: {
61-
clientMutationId:"uniqueId"
62-
username: "your_login"
65+
clientMutationId: "uniqueId",
66+
username: "your_login",
6367
password: "your password"
6468
} ) {
6569
authToken
@@ -71,13 +75,52 @@ mutation LoginUser {
7175
}
7276
```
7377

74-
The `authToken` that is received in response to the login mutation can then be stored in local storage (or similar) and
75-
used in subsequent requests as an HTTP Authorization header to Authenticate the user prior to execution of the
76-
GraphQL request.
78+
The `authToken` that is received in response to the login mutation can then be stored in local storage (or similar) and
79+
used in subsequent requests as an HTTP Authorization header to Authenticate the user prior to execution of the
80+
GraphQL request.
7781

7882
- **Set authorization header in Apollo Client**: https://www.apollographql.com/docs/react/networking/authentication/#header
7983
- **Set authorization header in Relay Modern**: https://relay.dev/docs/en/network-layer.html
8084
- **Set authorization header in Axios**: https://github.com/axios/axios#axioscreateconfig
8185

86+
87+
### Register User
88+
89+
**Input-Type:** `RegisterUserInput!`
90+
91+
```graphql
92+
mutation RegisterUser {
93+
registerUser(
94+
input: {
95+
clientMutationId: "uniqueId",
96+
username: "your_username",
97+
password: "your_password",
98+
email: "your_email"
99+
}) {
100+
user {
101+
jwtAuthToken
102+
jwtRefreshToken
103+
}
104+
}
105+
}
106+
```
107+
108+
### Refresh Auth Token
109+
110+
**Input-Type:** `RefreshJwtAuthTokenInput!`
111+
112+
```graphql
113+
mutation RefreshAuthToken {
114+
refreshJwtAuthToken(
115+
input: {
116+
clientMutationId: "uniqueId"
117+
jwtRefreshToken: "your_refresh_token",
118+
}) {
119+
authToken
120+
}
121+
}
122+
```
123+
124+
82125
## Example using GraphiQL
83126
![Example using GraphiQL](https://github.com/wp-graphql/wp-graphql-jwt-authentication/blob/master/img/jwt-auth-example.gif?raw=true)

src/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public static function get_refresh_token( $user, $cap_check = true ) {
320320
*/
321321
add_filter( 'graphql_jwt_auth_token_before_sign', function( $token, \WP_User $user ) {
322322
$secret = Auth::get_user_jwt_secret( $user->ID );
323-
323+
324324
if ( ! empty( $secret ) && ! is_wp_error( $secret ) && true === self::is_refresh_token() ) {
325325

326326
/**

0 commit comments

Comments
 (0)