Skip to content

Fix style for consistency #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ Example
use Firebase\JWT\JWT;
use Firebase\JWT\Key;

$key = "example_key";
$payload = array(
"iss" => "http://example.org",
"aud" => "http://example.com",
"iat" => 1356999524,
"nbf" => 1357000000
);
$key = 'example_key';
$payload = [
'iss' => 'http://example.org',
'aud' => 'http://example.com',
'iat' => 1356999524,
'nbf' => 1357000000
];

/**
* IMPORTANT:
Expand Down Expand Up @@ -98,12 +98,12 @@ ehde/zUxo6UvS7UrBQIDAQAB
-----END PUBLIC KEY-----
EOD;

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

$jwt = JWT::encode($payload, $privateKey, 'RS256');
echo "Encode:\n" . print_r($jwt, true) . "\n";
Expand Down Expand Up @@ -139,12 +139,12 @@ $privateKey = openssl_pkey_get_private(
$passphrase
);

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

$jwt = JWT::encode($payload, $privateKey, 'RS256');
echo "Encode:\n" . print_r($jwt, true) . "\n";
Expand Down Expand Up @@ -173,12 +173,12 @@ $privateKey = base64_encode(sodium_crypto_sign_secretkey($keyPair));

$publicKey = base64_encode(sodium_crypto_sign_publickey($keyPair));

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

$jwt = JWT::encode($payload, $privateKey, 'EdDSA');
echo "Encode:\n" . print_r($jwt, true) . "\n";
Expand Down
2 changes: 1 addition & 1 deletion src/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public static function sign(
$signature = '';
$success = \openssl_sign($msg, $signature, $key, $algorithm); // @phpstan-ignore-line
if (!$success) {
throw new DomainException("OpenSSL unable to sign data");
throw new DomainException('OpenSSL unable to sign data');
}
if ($alg === 'ES256') {
$signature = self::signatureFromDER($signature, 256);
Expand Down
4 changes: 2 additions & 2 deletions tests/JWKTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function testDecodeByJwkKeySet()

$result = JWT::decode($msg, self::$keys);

$this->assertEquals("foo", $result->sub);
$this->assertEquals('foo', $result->sub);
}

/**
Expand All @@ -139,6 +139,6 @@ public function testDecodeByMultiJwkKeySet()

$result = JWT::decode($msg, self::$keys);

$this->assertEquals("bar", $result->sub);
$this->assertEquals('bar', $result->sub);
}
}
44 changes: 22 additions & 22 deletions tests/JWTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function testExpiredToken()
{
$this->expectException(ExpiredException::class);
$payload = [
"message" => "abc",
"exp" => time() - 20]; // time in the past
'message' => 'abc',
'exp' => time() - 20]; // time in the past
$encoded = JWT::encode($payload, 'my_key', 'HS256');
JWT::decode($encoded, new Key('my_key', 'HS256'));
}
Expand All @@ -46,7 +46,7 @@ public function testBeforeValidTokenWithNbf()
{
$this->expectException(BeforeValidException::class);
$payload = [
"message" => "abc",
'message' => 'abc',
"nbf" => time() + 20]; // time in the future
$encoded = JWT::encode($payload, 'my_key', 'HS256');
JWT::decode($encoded, new Key('my_key', 'HS256'));
Expand All @@ -56,7 +56,7 @@ public function testBeforeValidTokenWithIat()
{
$this->expectException(BeforeValidException::class);
$payload = [
"message" => "abc",
'message' => 'abc',
"iat" => time() + 20]; // time in the future
$encoded = JWT::encode($payload, 'my_key', 'HS256');
JWT::decode($encoded, new Key('my_key', 'HS256'));
Expand All @@ -65,8 +65,8 @@ public function testBeforeValidTokenWithIat()
public function testValidToken()
{
$payload = [
"message" => "abc",
"exp" => time() + JWT::$leeway + 20]; // time in the future
'message' => 'abc',
'exp' => time() + JWT::$leeway + 20]; // time in the future
$encoded = JWT::encode($payload, 'my_key', 'HS256');
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
$this->assertEquals($decoded->message, 'abc');
Expand All @@ -76,8 +76,8 @@ public function testValidTokenWithLeeway()
{
JWT::$leeway = 60;
$payload = [
"message" => "abc",
"exp" => time() - 20]; // time in the past
'message' => 'abc',
'exp' => time() - 20]; // time in the past
$encoded = JWT::encode($payload, 'my_key', 'HS256');
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
$this->assertEquals($decoded->message, 'abc');
Expand All @@ -88,8 +88,8 @@ public function testExpiredTokenWithLeeway()
{
JWT::$leeway = 60;
$payload = [
"message" => "abc",
"exp" => time() - 70]; // time far in the past
'message' => 'abc',
'exp' => time() - 70]; // time far in the past
$this->expectException(ExpiredException::class);
$encoded = JWT::encode($payload, 'my_key', 'HS256');
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
Expand All @@ -100,9 +100,9 @@ public function testExpiredTokenWithLeeway()
public function testValidTokenWithNbf()
{
$payload = [
"message" => "abc",
'message' => 'abc',
"iat" => time(),
"exp" => time() + 20, // time in the future
'exp' => time() + 20, // time in the future
"nbf" => time() - 20];
$encoded = JWT::encode($payload, 'my_key', 'HS256');
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
Expand All @@ -113,7 +113,7 @@ public function testValidTokenWithNbfLeeway()
{
JWT::$leeway = 60;
$payload = [
"message" => "abc",
'message' => 'abc',
"nbf" => time() + 20]; // not before in near (leeway) future
$encoded = JWT::encode($payload, 'my_key', 'HS256');
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
Expand All @@ -125,7 +125,7 @@ public function testInvalidTokenWithNbfLeeway()
{
JWT::$leeway = 60;
$payload = [
"message" => "abc",
'message' => 'abc',
"nbf" => time() + 65]; // not before too far in future
$encoded = JWT::encode($payload, 'my_key', 'HS256');
$this->expectException(BeforeValidException::class);
Expand All @@ -137,7 +137,7 @@ public function testValidTokenWithIatLeeway()
{
JWT::$leeway = 60;
$payload = [
"message" => "abc",
'message' => 'abc',
"iat" => time() + 20]; // issued in near (leeway) future
$encoded = JWT::encode($payload, 'my_key', 'HS256');
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
Expand All @@ -149,7 +149,7 @@ public function testInvalidTokenWithIatLeeway()
{
JWT::$leeway = 60;
$payload = [
"message" => "abc",
'message' => 'abc',
"iat" => time() + 65]; // issued too far in future
$encoded = JWT::encode($payload, 'my_key', 'HS256');
$this->expectException(BeforeValidException::class);
Expand All @@ -160,8 +160,8 @@ public function testInvalidTokenWithIatLeeway()
public function testInvalidToken()
{
$payload = [
"message" => "abc",
"exp" => time() + 20]; // time in the future
'message' => 'abc',
'exp' => time() + 20]; // time in the future
$encoded = JWT::encode($payload, 'my_key', 'HS256');
$this->expectException(SignatureInvalidException::class);
JWT::decode($encoded, new Key('my_key2', 'HS256'));
Expand All @@ -170,8 +170,8 @@ public function testInvalidToken()
public function testNullKeyFails()
{
$payload = [
"message" => "abc",
"exp" => time() + JWT::$leeway + 20]; // time in the future
'message' => 'abc',
'exp' => time() + JWT::$leeway + 20]; // time in the future
$encoded = JWT::encode($payload, 'my_key', 'HS256');
$this->expectException(TypeError::class);
JWT::decode($encoded, new Key(null, 'HS256'));
Expand All @@ -180,8 +180,8 @@ public function testNullKeyFails()
public function testEmptyKeyFails()
{
$payload = [
"message" => "abc",
"exp" => time() + JWT::$leeway + 20]; // time in the future
'message' => 'abc',
'exp' => time() + JWT::$leeway + 20]; // time in the future
$encoded = JWT::encode($payload, 'my_key', 'HS256');
$this->expectException(InvalidArgumentException::class);
JWT::decode($encoded, new Key('', 'HS256'));
Expand Down