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

Fix update error #17

Merged
merged 5 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
composer.phar
composer.lock
.DS_Store
.idea
colq2 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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);
Expand Down Expand Up @@ -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);
}
}