Skip to content

Commit

Permalink
Merge pull request #93 from wp-graphql/release/v0.4.1
Browse files Browse the repository at this point in the history
Release/v0.4.1
  • Loading branch information
jasonbahl authored May 4, 2020
2 parents e65055d + feea336 commit 7905ab9
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 155 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ mutation RefreshAuthToken {
}
```

## Filters

The plugin offers some filters to hook into.

### Change Auth Token expiration

**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.**

```php
add_filter('graphql_jwt_auth_expire', 60);
```

- Argument: Expiration in seconds
- Default: 300


## Example using GraphiQL
![Example using GraphiQL](https://github.com/wp-graphql/wp-graphql-jwt-authentication/blob/master/img/jwt-auth-example.gif?raw=true)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"wpunit-test": "vendor/bin/codecept run wpunit"
},
"require": {
"firebase/php-jwt": "^4.0"
"firebase/php-jwt": "^5.0"
},
"require-dev": {
"lucatume/wp-browser": ">=2.2.1 <2.2.8"
Expand Down
10 changes: 4 additions & 6 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Auth {
public static function get_secret_key() {

// Use the defined secret key, if it exists
$secret_key = defined( 'GRAPHQL_JWT_AUTH_SECRET_KEY' ) && ! empty( GRAPHQL_JWT_AUTH_SECRET_KEY ) ? GRAPHQL_JWT_AUTH_SECRET_KEY : 'graphql-jwt-auth';
$secret_key = defined( 'GRAPHQL_JWT_AUTH_SECRET_KEY' ) && ! empty( GRAPHQL_JWT_AUTH_SECRET_KEY ) ? GRAPHQL_JWT_AUTH_SECRET_KEY : null;
return apply_filters( 'graphql_jwt_auth_secret_key', $secret_key );

}
Expand Down Expand Up @@ -105,19 +105,17 @@ public static function get_token_expiration() {
/**
* Set the expiration time, default is 300 seconds.
*/
$expiration = self::get_token_issued() + 300;
$expiration = 300;

/**
* Determine the expiration value. Default is 7 days, but is filterable to be configured as needed
* Determine the expiration value. Default is 5 minutes, but is filterable to be configured as needed
*
* @param string $expiration The timestamp for when the token should expire
*/
self::$expiration = apply_filters( 'graphql_jwt_auth_expire', $expiration );

self::$expiration = self::get_token_issued() + apply_filters( 'graphql_jwt_auth_expire', $expiration );
}

return ! empty( self::$expiration ) ? self::$expiration : null;

}

/**
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit2bca884894f5dad38a04fb4589efa493::getLoader();
return ComposerAutoloaderInitb81212723df6ec6a4125604686c14dbf::getLoader();
8 changes: 4 additions & 4 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit2bca884894f5dad38a04fb4589efa493
class ComposerAutoloaderInitb81212723df6ec6a4125604686c14dbf
{
private static $loader;

Expand All @@ -19,15 +19,15 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInit2bca884894f5dad38a04fb4589efa493', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitb81212723df6ec6a4125604686c14dbf', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit2bca884894f5dad38a04fb4589efa493', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitb81212723df6ec6a4125604686c14dbf', 'loadClassLoader'));

$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';

call_user_func(\Composer\Autoload\ComposerStaticInit2bca884894f5dad38a04fb4589efa493::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitb81212723df6ec6a4125604686c14dbf::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit2bca884894f5dad38a04fb4589efa493
class ComposerStaticInitb81212723df6ec6a4125604686c14dbf
{
public static $prefixLengthsPsr4 = array (
'W' =>
Expand Down Expand Up @@ -42,9 +42,9 @@ class ComposerStaticInit2bca884894f5dad38a04fb4589efa493
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit2bca884894f5dad38a04fb4589efa493::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit2bca884894f5dad38a04fb4589efa493::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit2bca884894f5dad38a04fb4589efa493::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitb81212723df6ec6a4125604686c14dbf::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitb81212723df6ec6a4125604686c14dbf::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitb81212723df6ec6a4125604686c14dbf::$classMap;

}, null, ClassLoader::class);
}
Expand Down
15 changes: 9 additions & 6 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
[
{
"name": "firebase/php-jwt",
"version": "v4.0.0",
"version_normalized": "4.0.0.0",
"version": "v5.1.0",
"version_normalized": "5.1.0.0",
"source": {
"type": "git",
"url": "https://github.com/firebase/php-jwt.git",
"reference": "dccf163dc8ed7ed6a00afc06c51ee5186a428d35"
"reference": "4566062c68f76f43d44f1643f4970fe89757d4c6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/dccf163dc8ed7ed6a00afc06c51ee5186a428d35",
"reference": "dccf163dc8ed7ed6a00afc06c51ee5186a428d35",
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/4566062c68f76f43d44f1643f4970fe89757d4c6",
"reference": "4566062c68f76f43d44f1643f4970fe89757d4c6",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2016-07-18T04:51:16+00:00",
"require-dev": {
"phpunit/phpunit": "^4.8|^5"
},
"time": "2020-02-24T23:15:03+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
Expand Down
85 changes: 83 additions & 2 deletions vendor/firebase/php-jwt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Example
use \Firebase\JWT\JWT;

$key = "example_key";
$token = array(
$payload = array(
"iss" => "http://example.org",
"aud" => "http://example.com",
"iat" => 1356999524,
Expand All @@ -36,7 +36,7 @@ $token = array(
* https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40
* for a list of spec-compliant algorithms.
*/
$jwt = JWT::encode($token, $key);
$jwt = JWT::encode($payload, $key);
$decoded = JWT::decode($jwt, $key, array('HS256'));

print_r($decoded);
Expand All @@ -58,12 +58,87 @@ $decoded_array = (array) $decoded;
JWT::$leeway = 60; // $leeway in seconds
$decoded = JWT::decode($jwt, $key, array('HS256'));

?>
```
Example with RS256 (openssl)
----------------------------
```php
<?php
use \Firebase\JWT\JWT;

$privateKey = <<<EOD
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQC8kGa1pSjbSYZVebtTRBLxBz5H4i2p/llLCrEeQhta5kaQu/Rn
vuER4W8oDH3+3iuIYW4VQAzyqFpwuzjkDI+17t5t0tyazyZ8JXw+KgXTxldMPEL9
5+qVhgXvwtihXC1c5oGbRlEDvDF6Sa53rcFVsYJ4ehde/zUxo6UvS7UrBQIDAQAB
AoGAb/MXV46XxCFRxNuB8LyAtmLDgi/xRnTAlMHjSACddwkyKem8//8eZtw9fzxz
bWZ/1/doQOuHBGYZU8aDzzj59FZ78dyzNFoF91hbvZKkg+6wGyd/LrGVEB+Xre0J
Nil0GReM2AHDNZUYRv+HYJPIOrB0CRczLQsgFJ8K6aAD6F0CQQDzbpjYdx10qgK1
cP59UHiHjPZYC0loEsk7s+hUmT3QHerAQJMZWC11Qrn2N+ybwwNblDKv+s5qgMQ5
5tNoQ9IfAkEAxkyffU6ythpg/H0Ixe1I2rd0GbF05biIzO/i77Det3n4YsJVlDck
ZkcvY3SK2iRIL4c9yY6hlIhs+K9wXTtGWwJBAO9Dskl48mO7woPR9uD22jDpNSwe
k90OMepTjzSvlhjbfuPN1IdhqvSJTDychRwn1kIJ7LQZgQ8fVz9OCFZ/6qMCQGOb
qaGwHmUK6xzpUbbacnYrIM6nLSkXgOAwv7XXCojvY614ILTK3iXiLBOxPu5Eu13k
eUz9sHyD6vkgZzjtxXECQAkp4Xerf5TGfQXGXhxIX52yH+N2LtujCdkQZjXAsGdm
B2zNzvrlgRmgBrklMTrMYgm1NPcW+bRLGcwgW2PTvNM=
-----END RSA PRIVATE KEY-----
EOD;

$publicKey = <<<EOD
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8kGa1pSjbSYZVebtTRBLxBz5H
4i2p/llLCrEeQhta5kaQu/RnvuER4W8oDH3+3iuIYW4VQAzyqFpwuzjkDI+17t5t
0tyazyZ8JXw+KgXTxldMPEL95+qVhgXvwtihXC1c5oGbRlEDvDF6Sa53rcFVsYJ4
ehde/zUxo6UvS7UrBQIDAQAB
-----END PUBLIC KEY-----
EOD;

$payload = array(
"iss" => "example.org",
"aud" => "example.com",
"iat" => 1356999524,
"nbf" => 1357000000
);

$jwt = JWT::encode($payload, $privateKey, 'RS256');
echo "Encode:\n" . print_r($jwt, true) . "\n";

$decoded = JWT::decode($jwt, $publicKey, array('RS256'));

/*
NOTE: This will now be an object instead of an associative array. To get
an associative array, you will need to cast it as such:
*/

$decoded_array = (array) $decoded;
echo "Decode:\n" . print_r($decoded_array, true) . "\n";
?>
```

Changelog
---------

#### 5.0.0 / 2017-06-26
- Support RS384 and RS512.
See [#117](https://github.com/firebase/php-jwt/pull/117). Thanks [@joostfaassen](https://github.com/joostfaassen)!
- Add an example for RS256 openssl.
See [#125](https://github.com/firebase/php-jwt/pull/125). Thanks [@akeeman](https://github.com/akeeman)!
- Detect invalid Base64 encoding in signature.
See [#162](https://github.com/firebase/php-jwt/pull/162). Thanks [@psignoret](https://github.com/psignoret)!
- Update `JWT::verify` to handle OpenSSL errors.
See [#159](https://github.com/firebase/php-jwt/pull/159). Thanks [@bshaffer](https://github.com/bshaffer)!
- Add `array` type hinting to `decode` method
See [#101](https://github.com/firebase/php-jwt/pull/101). Thanks [@hywak](https://github.com/hywak)!
- Add all JSON error types.
See [#110](https://github.com/firebase/php-jwt/pull/110). Thanks [@gbalduzzi](https://github.com/gbalduzzi)!
- Bugfix 'kid' not in given key list.
See [#129](https://github.com/firebase/php-jwt/pull/129). Thanks [@stampycode](https://github.com/stampycode)!
- Miscellaneous cleanup, documentation and test fixes.
See [#107](https://github.com/firebase/php-jwt/pull/107), [#115](https://github.com/firebase/php-jwt/pull/115),
[#160](https://github.com/firebase/php-jwt/pull/160), [#161](https://github.com/firebase/php-jwt/pull/161), and
[#165](https://github.com/firebase/php-jwt/pull/165). Thanks [@akeeman](https://github.com/akeeman),
[@chinedufn](https://github.com/chinedufn), and [@bshaffer](https://github.com/bshaffer)!

#### 4.0.0 / 2016-07-17
- Add support for late static binding. See [#88](https://github.com/firebase/php-jwt/pull/88) for details. Thanks to [@chappy84](https://github.com/chappy84)!
- Use static `$timestamp` instead of `time()` to improve unit testing. See [#93](https://github.com/firebase/php-jwt/pull/93) for details. Thanks to [@josephmcdermott](https://github.com/josephmcdermott)!
Expand Down Expand Up @@ -114,6 +189,12 @@ Time: 0 seconds, Memory: 2.50Mb
OK (5 tests, 5 assertions)
```

New Lines in private keys
-----

If your private key contains `\n` characters, be sure to wrap it in double quotes `""`
and not single quotes `''` in order to properly interpret the escaped characters.

License
-------
[3-Clause BSD](http://opensource.org/licenses/BSD-3-Clause).
4 changes: 3 additions & 1 deletion vendor/firebase/php-jwt/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@
"Firebase\\JWT\\": "src"
}
},
"minimum-stability": "dev"
"require-dev": {
"phpunit/phpunit": "^4.8|^5"
}
}
19 changes: 0 additions & 19 deletions vendor/firebase/php-jwt/composer.lock

This file was deleted.

77 changes: 0 additions & 77 deletions vendor/firebase/php-jwt/package.xml

This file was deleted.

Loading

0 comments on commit 7905ab9

Please sign in to comment.