Skip to content

Commit

Permalink
Merge pull request #17 from colq2/fix-update-error
Browse files Browse the repository at this point in the history
Fix update error
  • Loading branch information
mstefan21 authored Jun 21, 2021
2 parents 4d4b4ae + 35fb6d5 commit 2860f17
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/build
/vendor
composer.phar
composer.lock
.DS_Store
composer.lock
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ php:
- 5.6
- 7.0
- 7.1
- hhvm

matrix:
include:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
34 changes: 34 additions & 0 deletions src/Provider/Keycloak.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -222,11 +223,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);
Expand Down Expand Up @@ -288,4 +296,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);
}
}

0 comments on commit 2860f17

Please sign in to comment.