From ac9ab4cbf43eec1c24d4003c1e3ced7f21852703 Mon Sep 17 00:00:00 2001 From: Oliver Wycisk Date: Tue, 12 Mar 2019 13:00:05 +0100 Subject: [PATCH 1/5] Update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9c9c8f2..c70ec65 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.phar composer.lock .DS_Store +.idea \ No newline at end of file From a927200339f26cc29136171441ac4af64fd850a8 Mon Sep 17 00:00:00 2001 From: Oliver Wycisk Date: Tue, 12 Mar 2019 16:23:53 +0100 Subject: [PATCH 2/5] Fixed update oauth-client to 2.4 error --- composer.json | 2 +- src/Provider/Keycloak.php | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 324611a..6b28ab5 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "keycloak" ], "require": { - "league/oauth2-client": "^2.0 <2.3.0", + "league/oauth2-client": "^2.0", "firebase/php-jwt": "^4.0" }, "require-dev": { diff --git a/src/Provider/Keycloak.php b/src/Provider/Keycloak.php index 57cd922..38937f4 100644 --- a/src/Provider/Keycloak.php +++ b/src/Provider/Keycloak.php @@ -10,6 +10,7 @@ use League\OAuth2\Client\Tool\BearerAuthorizationTrait; use Psr\Http\Message\ResponseInterface; use Stevenmaguire\OAuth2\Client\Provider\Exception\EncryptionConfigurationException; +use UnexpectedValueException; class Keycloak extends AbstractProvider { @@ -210,11 +211,18 @@ protected function createResourceOwner(array $response, AccessToken $token) * * @param AccessToken $token * @return KeycloakResourceOwner + * @throws EncryptionConfigurationException */ public function getResourceOwner(AccessToken $token) { $response = $this->fetchResourceOwnerDetails($token); + // We are always getting an array. We have to check if it is + // the array we created + if (array_key_exists('jwt', $response)) { + $response = $response['jwt']; + } + $response = $this->decryptResponse($response); return $this->createResourceOwner($response, $token); @@ -276,4 +284,30 @@ public function usesEncryption() { return (bool) $this->encryptionAlgorithm && $this->encryptionKey; } + + /** + * Parses the response according to its content-type header. + * + * @throws UnexpectedValueException + * @param ResponseInterface $response + * @return array + */ + protected function parseResponse(ResponseInterface $response) + { + // We have a problem with keycloak when the userinfo responses + // with a jwt token + // Because it just return a jwt as string with the header + // application/jwt + // This can't be parsed to a array + // Dont know why this function only allow an array as return value... + $content = (string) $response->getBody(); + $type = $this->getContentType($response); + + if (strpos($type, 'jwt') !== false) { + // Here we make the temporary array + return ['jwt' => $content]; + } + + return parent::parseResponse($response); + } } From 4e2335e15a96c74c8d10206ac56b53c0df387d3f Mon Sep 17 00:00:00 2001 From: Oliver Wycisk Date: Tue, 12 Mar 2019 16:49:39 +0100 Subject: [PATCH 3/5] Removed hhvm because Facebook dropped support. See: https://github.com/composer/composer/issues/7990 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d99d282..87831a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ php: - 5.6 - 7.0 - 7.1 - - hhvm matrix: include: From ba757de0a80268d66754f6fb946f1787bb6c55ea Mon Sep 17 00:00:00 2001 From: Oliver Wycisk Date: Thu, 23 Jul 2020 11:26:02 +0200 Subject: [PATCH 4/5] removed .idea from local gitignore to global gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c70ec65..84dbf92 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ /vendor composer.phar composer.lock -.DS_Store -.idea \ No newline at end of file +.DS_Store \ No newline at end of file From 35fb6d57696d0907d31f4fcda88cec8174d020d0 Mon Sep 17 00:00:00 2001 From: Oliver Wycisk Date: Fri, 24 Jul 2020 12:05:30 +0200 Subject: [PATCH 5/5] removed .DS_Store from gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 84dbf92..e8c7cb6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /build /vendor composer.phar -composer.lock -.DS_Store \ No newline at end of file +composer.lock \ No newline at end of file