File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class Auth {
23
23
public static function get_secret_key () {
24
24
25
25
// Use the defined secret key, if it exists
26
- $ secret_key = defined ( 'GRAPHQL_JWT_AUTH_SECRET_KEY ' ) && ! empty ( GRAPHQL_JWT_AUTH_SECRET_KEY ) ? GRAPHQL_JWT_AUTH_SECRET_KEY : ' graphql-jwt-auth ' ;
26
+ $ secret_key = defined ( 'GRAPHQL_JWT_AUTH_SECRET_KEY ' ) && ! empty ( GRAPHQL_JWT_AUTH_SECRET_KEY ) ? GRAPHQL_JWT_AUTH_SECRET_KEY : null ;
27
27
return apply_filters ( 'graphql_jwt_auth_secret_key ' , $ secret_key );
28
28
29
29
}
Original file line number Diff line number Diff line change @@ -189,12 +189,20 @@ private static function init() {
189
189
* response status to 403.
190
190
*/
191
191
add_action ( 'init_graphql_request ' , function () {
192
- $ token = Auth::validate_token ();
193
- if ( is_wp_error ( $ token ) ) {
194
- add_action ( 'graphql_before_resolve_field ' , function () use ( $ token ) {
195
- throw new \Exception ( $ token ->get_error_code () . ' | ' . $ token ->get_error_message () );
196
- }, 1 );
192
+
193
+ $ jwt_secret = Auth::get_secret_key ();
194
+ if ( empty ( $ jwt_secret ) || 'graphql-jwt-auth ' === $ jwt_secret ) {
195
+ throw new \Exception ( __ ( 'You must define the GraphQL JWT Auth secret to use the WPGraphQL JWT Authentication plugin. ' , 'graphql-jwt-auth ' ) );
196
+ } else {
197
+ $ token = Auth::validate_token ();
198
+ if ( is_wp_error ( $ token ) ) {
199
+ add_action ( 'graphql_before_resolve_field ' , function () use ( $ token ) {
200
+ throw new \Exception ( $ token ->get_error_code () . ' | ' . $ token ->get_error_message () );
201
+ }, 1 );
202
+ }
197
203
}
204
+
205
+
198
206
} );
199
207
200
208
}
You can’t perform that action at this time.
0 commit comments