Skip to content

Commit 478e610

Browse files
authored
Merge pull request #83 from wp-graphql/feature/document-filters
Fix Auth Expiration time filter and add it to documentation
2 parents e65055d + 5edc698 commit 478e610

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@ mutation RefreshAuthToken {
121121
}
122122
```
123123

124+
## Filters
125+
126+
The plugin offers some filters to hook into.
127+
128+
### Change Auth Token expiration
129+
130+
**Note: For security, we highly recommend, that the Auth Token is short lived. So do not set this higher than 300 seconds unless you know what you are doing.**
131+
132+
```php
133+
add_filter('graphql_jwt_auth_expire', 60);
134+
```
135+
136+
- Argument: Expiration in seconds
137+
- Default: 300
138+
124139

125140
## Example using GraphiQL
126141
![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: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,17 @@ public static function get_token_expiration() {
105105
/**
106106
* Set the expiration time, default is 300 seconds.
107107
*/
108-
$expiration = self::get_token_issued() + 300;
108+
$expiration = 300;
109109

110110
/**
111-
* Determine the expiration value. Default is 7 days, but is filterable to be configured as needed
111+
* Determine the expiration value. Default is 5 minutes, but is filterable to be configured as needed
112112
*
113113
* @param string $expiration The timestamp for when the token should expire
114114
*/
115-
self::$expiration = apply_filters( 'graphql_jwt_auth_expire', $expiration );
116-
115+
self::$expiration = self::get_token_issued() + apply_filters( 'graphql_jwt_auth_expire', $expiration );
117116
}
118117

119118
return ! empty( self::$expiration ) ? self::$expiration : null;
120-
121119
}
122120

123121
/**

0 commit comments

Comments
 (0)