Skip to content
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

Alter JWT claims to use standard ones. #15

Merged
merged 2 commits into from
Nov 21, 2018
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
16 changes: 8 additions & 8 deletions src/Syn/JwtAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ public function getCredentials(Request $request)

// Check correct properties
$payload = $jwt->getPayload();
if (!isset($payload['uid'])) {
$this->logger->info('Token missing uid');
if (!isset($payload['webid'])) {
$this->logger->info('Token missing webid');
return null;
}
if (!isset($payload['url'])) {
$this->logger->info('Token missing url');
if (!isset($payload['iss'])) {
$this->logger->info('Token missing iss');
return null;
}
if (!isset($payload['name'])) {
$this->logger->info('Token missing name');
if (!isset($payload['sub'])) {
$this->logger->info('Token missing sub');
return null;
}
if (!isset($payload['roles'])) {
Expand All @@ -105,7 +105,7 @@ public function getCredentials(Request $request)
return [
'token' => $token,
'jwt' => $jwt,
'name' => $payload['name'],
'name' => $payload['sub'],
'roles' => $payload['roles']
];
}
Expand All @@ -126,7 +126,7 @@ public function checkCredentials($credentials, UserInterface $user)

$jwt = $credentials['jwt'];
$payload = $jwt->getPayload();
$url = $payload['url'];
$url = $payload['iss'];
if (isset($this->sites[$url])) {
$site = $this->sites[$url];
} elseif (isset($this->sites['default'])) {
Expand Down
36 changes: 18 additions & 18 deletions tests/Syn/JwtAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,25 +138,25 @@ public function headerTokenHelper($data, $expired = false)
public function testHeaderTokenFields()
{
$data = [
'uid' => 1,
'url' => 'https://foo.com',
'name' => 'charlie',
'webid' => 1,
'iss' => 'https://foo.com',
'sub' => 'charlie',
'roles' => ['bartender', 'exterminator'],
'iat' => 1,
'exp' => 1,
];
$this->assertTrue(is_array($this->headerTokenHelper($data)));

$missing = $data;
unset($missing['uid']);
unset($missing['webid']);
$this->assertNull($this->headerTokenHelper($missing));

$missing = $data;
unset($missing['url']);
unset($missing['iss']);
$this->assertNull($this->headerTokenHelper($missing));

$missing = $data;
unset($missing['name']);
unset($missing['sub']);
$this->assertNull($this->headerTokenHelper($missing));

$missing = $data;
Expand Down Expand Up @@ -203,9 +203,9 @@ public function jwtAuthHelper($data, $parser, $valid = true)
public function testJwtAuthentication()
{
$data = [
'uid' => 1,
'url' => 'https://foo.com',
'name' => 'charlie',
'webid' => 1,
'iss' => 'https://foo.com',
'sub' => 'charlie',
'roles' => ['bartender', 'exterminator'],
'iat' => 1,
'exp' => 1,
Expand All @@ -217,9 +217,9 @@ public function testJwtAuthentication()
public function testJwtAuthenticationInvalidJwt()
{
$data = [
'uid' => 1,
'url' => 'https://foo.com',
'name' => 'charlie',
'webid' => 1,
'iss' => 'https://foo.com',
'sub' => 'charlie',
'roles' => ['bartender', 'exterminator'],
'iat' => 1,
'exp' => 1,
Expand All @@ -231,9 +231,9 @@ public function testJwtAuthenticationInvalidJwt()
public function testJwtAuthenticationNoSite()
{
$data = [
'uid' => 1,
'url' => 'https://www.pattyspub.ca/',
'name' => 'charlie',
'webid' => 1,
'iss' => 'https://www.pattyspub.ca/',
'sub' => 'charlie',
'roles' => ['bartender', 'exterminator'],
'iat' => 1,
'exp' => 1,
Expand All @@ -245,9 +245,9 @@ public function testJwtAuthenticationNoSite()
public function testJwtAuthenticationDefaultSite()
{
$data = [
'uid' => 1,
'url' => 'https://www.pattyspub.ca/',
'name' => 'charlie',
'webid' => 1,
'iss' => 'https://www.pattyspub.ca/',
'sub' => 'charlie',
'roles' => ['bartender', 'exterminator'],
'iat' => 1,
'exp' => 1,
Expand Down