Skip to content

Commit 28166b3

Browse files
committed
no message
1 parent 7edb870 commit 28166b3

File tree

3 files changed

+8
-49
lines changed

3 files changed

+8
-49
lines changed

README.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ JSON Web Tokens are an open, industry standard [RFC 7519](https://tools.ietf.org
66

77
This plugin is based off the `wp-api-jwt-auth` plugin by Enrique Chavez (https://github.com/Tmeister), but modified specifically for use with the <a href="https://github.com/wp-graphql/wp-graphql" target="_blank">WPGraphQL</a> plugin.
88

9-
### IN ACTION
9+
## IN ACTION
1010

1111
![WPGraphQL JWT AUTH DEMO - LOGIN, RECEIVE TOKEN AND USER DATA](https://github.com/wp-graphql/wp-graphql-jwt-authentication/blob/master/wpgraphql-auth.gif?raw=true "LOGIN, RECEIVE TOKEN AND USER DATA")
1212

13-
### REQUIREMENTS
13+
## REQUIREMENTS
1414

15-
### WPGraphQL
15+
#### WPGraphQL
1616

1717
This plugin exists as an extension of <a href="https://github.com/wp-graphql/wp-graphql" target="_blank">WPGraphQL</a> and requires that plugin to be active.
1818

19-
### PHP
19+
#### PHP
2020

21-
**Minimum PHP version: 5.3**
21+
**Minimum PHP version: 5.5**
2222

23-
### PHP HTTP Authorization Header enabled
23+
#### PHP HTTP Authorization Header enabled
2424

2525
Check with your hosting provider to determine if the Authorization headers are supported or how to add support if they aren't.
2626

2727
### CONFIGURATION & ACTIVATION
28-
### Configure the Secret Key
28+
#### Configure the Secret Key
2929

3030
The JWT needs a **secret key** to sign the token this **secret key** must be unique and never revealed.
3131

@@ -37,14 +37,5 @@ define('GRAPHQL_JWT_AUTH_SECRET_KEY', 'your-top-secrect-key');
3737

3838
You can use a string from here https://api.wordpress.org/secret-key/1.1/salt/
3939

40-
### Configurate CORs Support
41-
42-
The **wp-graphql-jwt-authentication** plugin has the option to activate [CORs](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) support.
43-
44-
To enable the CORs Support edit your wp-config.php file and add a new constant called **GRAPHQL_JWT_AUTH_CORS_ENABLE**
45-
46-
`
47-
define('JWT_AUTH_CORS_ENABLE', true);
48-
`
4940

5041
Finally activate the plugin within your wp-admin.

src/Config.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ public function __construct() {
3131
*/
3232
self::$secret_key = self::get_secret_key();
3333

34-
/**
35-
* Add cors support to the header if enabled
36-
*/
37-
add_action( 'graphql_process_http_request', [ $this, 'add_cors_support' ] );
38-
3934
/**
4035
* Determine the current user
4136
*/
@@ -81,31 +76,6 @@ public static function get_secret_key() {
8176

8277
}
8378

84-
/**
85-
* If enabled, this will add "cors" support by adjusting the headers for the GraphQL request. This first
86-
* checks to see if the constant is defined, then passes it through a filter, allowing for that value to be
87-
* dynamic, for example an admin UI could be created that would allow for the option to be checked.
88-
*
89-
* @since 0.0.1
90-
* @return void
91-
*/
92-
public function add_cors_support() {
93-
94-
/**
95-
* Cors is disabled by default, but can be defined / filtered to be enabled
96-
*
97-
* @since 0.0.1
98-
*/
99-
$enable_cors = defined( 'GRAPHQL_JWT_AUTH_CORS_ENABLE' ) ? GRAPHQL_JWT_AUTH_CORS_ENABLE : false;
100-
$enable_cors = apply_filters( 'graphql_jwt_auth_enable_cors', $enable_cors );
101-
102-
if ( $enable_cors ) {
103-
$headers = apply_filters( 'graphql_jwt_auth_cors_allow_headers', 'Access-Control-Allow-Headers, Content-Type, Authorization' );
104-
header( sprintf( 'Access-Control-Allow-Headers: %s', $headers ) );
105-
}
106-
107-
}
108-
10979
/**
11080
* This is our Middleware to try to authenticate the user according to the
11181
* token send.

tests/test-authentication.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testLoginWithPage() {
5757
*/
5858
$query = '
5959
mutation {
60-
login(username: "testUser", password: "testPassword" ) {
60+
login( input: { username: "testUser", password: "testPassword" } ) {
6161
user {
6262
username
6363
pages{
@@ -78,8 +78,6 @@ public function testLoginWithPage() {
7878
*/
7979
$actual = do_graphql_request( $query );
8080

81-
var_dump( $actual['data']['login']['user']['pages']['edges'][0]['node'] );
82-
8381
/**
8482
* Establish the expectation for the output of the query
8583
*/

0 commit comments

Comments
 (0)