Skip to content

Commit

Permalink
Applied latest styles changes from style CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddanbrown committed Oct 16, 2021
1 parent 263384c commit 6e325de
Show file tree
Hide file tree
Showing 23 changed files with 177 additions and 147 deletions.
2 changes: 1 addition & 1 deletion app/Auth/Access/GroupSyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ public function syncUserWithFoundGroups(User $user, array $userGroups, bool $det
$user->roles()->syncWithoutDetaching($groupsAsRoles);
}
}
}
}
1 change: 1 addition & 0 deletions app/Auth/Access/LdapService.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public function getUserGroups(string $userName): array
}

$userGroups = $this->groupFilter($user);

return $this->getGroupsRecursive($userGroups, []);
}

Expand Down
7 changes: 3 additions & 4 deletions app/Auth/Access/Oidc/OidcAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class OidcAccessToken extends AccessToken
* Constructs an access token.
*
* @param array $options An array of options returned by the service provider
* in the access token request. The `access_token` option is required.
* in the access token request. The `access_token` option is required.
*
* @throws InvalidArgumentException if `access_token` is not provided in `$options`.
*/
public function __construct(array $options = [])
Expand All @@ -20,7 +21,6 @@ public function __construct(array $options = [])
$this->validate($options);
}


/**
* Validate this access token response for OIDC.
* As per https://openid.net/specs/openid-connect-basic-1_0.html#TokenOK.
Expand Down Expand Up @@ -50,5 +50,4 @@ public function getIdToken(): string
{
return $this->getValues()['id_token'];
}

}
}
18 changes: 12 additions & 6 deletions app/Auth/Access/Oidc/OidcIdToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected function parseEncodedTokenPart(string $part): array
{
$json = $this->base64UrlDecode($part) ?: '{}';
$decoded = json_decode($json, true);

return is_array($decoded) ? $decoded : [];
}

Expand All @@ -74,19 +75,22 @@ protected function base64UrlDecode(string $encoded): string

/**
* Validate all possible parts of the id token.
*
* @throws OidcInvalidTokenException
*/
public function validate(string $clientId): bool
{
$this->validateTokenStructure();
$this->validateTokenSignature();
$this->validateTokenClaims($clientId);

return true;
}

/**
* Fetch a specific claim from this token.
* Returns null if it is null or does not exist.
*
* @return mixed|null
*/
public function getClaim(string $claim)
Expand All @@ -104,7 +108,8 @@ public function getAllClaims(): array

/**
* Validate the structure of the given token and ensure we have the required pieces.
* As per https://datatracker.ietf.org/doc/html/rfc7519#section-7.2
* As per https://datatracker.ietf.org/doc/html/rfc7519#section-7.2.
*
* @throws OidcInvalidTokenException
*/
protected function validateTokenStructure(): void
Expand All @@ -116,12 +121,13 @@ protected function validateTokenStructure(): void
}

if (empty($this->signature) || !is_string($this->signature)) {
throw new OidcInvalidTokenException("Could not parse out a valid signature within the provided token");
throw new OidcInvalidTokenException('Could not parse out a valid signature within the provided token');
}
}

/**
* Validate the signature of the given token and ensure it validates against the provided key.
*
* @throws OidcInvalidTokenException
*/
protected function validateTokenSignature(): void
Expand All @@ -130,7 +136,7 @@ protected function validateTokenSignature(): void
throw new OidcInvalidTokenException("Only RS256 signature validation is supported. Token reports using {$this->header['alg']}");
}

$parsedKeys = array_map(function($key) {
$parsedKeys = array_map(function ($key) {
try {
return new OidcJwtSigningKey($key);
} catch (OidcInvalidKeyException $e) {
Expand All @@ -153,7 +159,8 @@ protected function validateTokenSignature(): void

/**
* Validate the claims of the token.
* As per https://openid.net/specs/openid-connect-basic-1_0.html#IDTokenValidation
* As per https://openid.net/specs/openid-connect-basic-1_0.html#IDTokenValidation.
*
* @throws OidcInvalidTokenException
*/
protected function validateTokenClaims(string $clientId): void
Expand Down Expand Up @@ -228,5 +235,4 @@ protected function validateTokenClaims(string $clientId): void
throw new OidcInvalidTokenException('Missing token subject value');
}
}

}
}
3 changes: 1 addition & 2 deletions app/Auth/Access/Oidc/OidcInvalidKeyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class OidcInvalidKeyException extends \Exception
{

}
}
3 changes: 1 addition & 2 deletions app/Auth/Access/Oidc/OidcInvalidTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class OidcInvalidTokenException extends Exception
{

}
}
3 changes: 1 addition & 2 deletions app/Auth/Access/Oidc/OidcIssuerDiscoveryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class OidcIssuerDiscoveryException extends \Exception
{

}
}
11 changes: 6 additions & 5 deletions app/Auth/Access/Oidc/OidcJwtSigningKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ class OidcJwtSigningKey
* Can be created either from a JWK parameter array or local file path to load a certificate from.
* Examples:
* 'file:///var/www/cert.pem'
* ['kty' => 'RSA', 'alg' => 'RS256', 'n' => 'abc123...']
* ['kty' => 'RSA', 'alg' => 'RS256', 'n' => 'abc123...'].
*
* @param array|string $jwkOrKeyPath
*
* @throws OidcInvalidKeyException
*/
public function __construct($jwkOrKeyPath)
{
if (is_array($jwkOrKeyPath)) {
$this->loadFromJwkArray($jwkOrKeyPath);
} else if (is_string($jwkOrKeyPath) && strpos($jwkOrKeyPath, 'file://') === 0) {
} elseif (is_string($jwkOrKeyPath) && strpos($jwkOrKeyPath, 'file://') === 0) {
$this->loadFromPath($jwkOrKeyPath);
} else {
throw new OidcInvalidKeyException('Unexpected type of key value provided');
Expand All @@ -47,7 +49,7 @@ protected function loadFromPath(string $path)
}

if (!($this->key instanceof RSA)) {
throw new OidcInvalidKeyException("Key loaded from file path is not an RSA key as expected");
throw new OidcInvalidKeyException('Key loaded from file path is not an RSA key as expected');
}
}

Expand Down Expand Up @@ -104,5 +106,4 @@ public function toPem(): string
{
return $this->key->toString('PKCS8');
}

}
}
18 changes: 9 additions & 9 deletions app/Auth/Access/Oidc/OidcOAuthProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class OidcOAuthProvider extends AbstractProvider
*/
protected $tokenEndpoint;


/**
* Returns the base URL for authorizing a client.
*/
Expand Down Expand Up @@ -66,7 +65,6 @@ protected function getDefaultScopes(): array
return ['openid', 'profile', 'email'];
}


/**
* Returns the string that should be used to separate scopes when building
* the URL for requesting an access token.
Expand All @@ -80,9 +78,11 @@ protected function getScopeSeparator(): string
* Checks a provider response for errors.
*
* @param ResponseInterface $response
* @param array|string $data Parsed response data
* @return void
* @param array|string $data Parsed response data
*
* @throws IdentityProviderException
*
* @return void
*/
protected function checkResponse(ResponseInterface $response, $data)
{
Expand All @@ -99,8 +99,9 @@ protected function checkResponse(ResponseInterface $response, $data)
* Generates a resource owner object from a successful resource owner
* details request.
*
* @param array $response
* @param array $response
* @param AccessToken $token
*
* @return ResourceOwnerInterface
*/
protected function createResourceOwner(array $response, AccessToken $token)
Expand All @@ -114,14 +115,13 @@ protected function createResourceOwner(array $response, AccessToken $token)
* The grant that was used to fetch the response can be used to provide
* additional context.
*
* @param array $response
* @param array $response
* @param AbstractGrant $grant
*
* @return OidcAccessToken
*/
protected function createAccessToken(array $response, AbstractGrant $grant)
{
return new OidcAccessToken($response);
}


}
}
17 changes: 11 additions & 6 deletions app/Auth/Access/Oidc/OidcProviderSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected function applySettingsFromArray(array $settingsArray)

/**
* Validate any core, required properties have been set.
*
* @throws InvalidArgumentException
*/
protected function validateInitial()
Expand All @@ -82,12 +83,13 @@ protected function validateInitial()
}

if (strpos($this->issuer, 'https://') !== 0) {
throw new InvalidArgumentException("Issuer value must start with https://");
throw new InvalidArgumentException('Issuer value must start with https://');
}
}

/**
* Perform a full validation on these settings.
*
* @throws InvalidArgumentException
*/
public function validate(): void
Expand All @@ -103,13 +105,14 @@ public function validate(): void

/**
* Discover and autoload settings from the configured issuer.
*
* @throws OidcIssuerDiscoveryException
*/
public function discoverFromIssuer(ClientInterface $httpClient, Repository $cache, int $cacheMinutes)
{
try {
$cacheKey = 'oidc-discovery::' . $this->issuer;
$discoveredSettings = $cache->remember($cacheKey, $cacheMinutes * 60, function() use ($httpClient) {
$discoveredSettings = $cache->remember($cacheKey, $cacheMinutes * 60, function () use ($httpClient) {
return $this->loadSettingsFromIssuerDiscovery($httpClient);
});
$this->applySettingsFromArray($discoveredSettings);
Expand All @@ -134,7 +137,7 @@ protected function loadSettingsFromIssuerDiscovery(ClientInterface $httpClient):
}

if ($result['issuer'] !== $this->issuer) {
throw new OidcIssuerDiscoveryException("Unexpected issuer value found on discovery response");
throw new OidcIssuerDiscoveryException('Unexpected issuer value found on discovery response');
}

$discoveredSettings = [];
Expand All @@ -160,13 +163,14 @@ protected function loadSettingsFromIssuerDiscovery(ClientInterface $httpClient):
*/
protected function filterKeys(array $keys): array
{
return array_filter($keys, function(array $key) {
return array_filter($keys, function (array $key) {
return $key['kty'] === 'RSA' && $key['use'] === 'sig' && $key['alg'] === 'RS256';
});
}

/**
* Return an array of jwks as PHP key=>value arrays.
*
* @throws ClientExceptionInterface
* @throws OidcIssuerDiscoveryException
*/
Expand All @@ -177,7 +181,7 @@ protected function loadKeysFromUri(string $uri, ClientInterface $httpClient): ar
$result = json_decode($response->getBody()->getContents(), true);

if (empty($result) || !is_array($result) || !isset($result['keys'])) {
throw new OidcIssuerDiscoveryException("Error reading keys from issuer jwks_uri");
throw new OidcIssuerDiscoveryException('Error reading keys from issuer jwks_uri');
}

return $result['keys'];
Expand All @@ -193,6 +197,7 @@ public function arrayForProvider(): array
foreach ($settingKeys as $setting) {
$settings[$setting] = $this->$setting;
}

return $settings;
}
}
}
Loading

0 comments on commit 6e325de

Please sign in to comment.