Skip to content

Commit

Permalink
Merge pull request #3 from ronvanderheijden/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
ronvanderheijden committed Mar 17, 2021
2 parents 3472f12 + fee9d02 commit a1b2b4f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.gitattributes export-ignore
.gitignore export-ignore
phpunit.xml export-ignore
.github/ export-ignore
example/ export-ignore
tests/ export-ignore
esc.php export-ignore
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ vendor/
.phpunit.result.cache
composer.lock
tmp/
dev/
.phplint-cache
phpd.log
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ I recommand to [read this](https://oauth2.thephpleague.com/authorization-server/
## Setup
```sh
# start the service application
php -S localhost:8000 -t example > phpd.log 2>&1 &
php -S localhost:8000 -t example

# get the tokens using the client
php example/get_tokens
Expand Down
20 changes: 10 additions & 10 deletions example/get_tokens
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ $tokensUrl = 'http://localhost:8000/tokens';
$redirectUrl = 'http://example.com/callback';

/**
* Your client ID, given by the Auth Provider.
* The client ID, given by the Auth Provider.
*/
$clientId = '1';

/**
* The scopes you want to collect.
* Add `openid` to get an id_token.
* Provider more scopes to receive additional claims in the id_token.
* Provide more scopes to receive additional claims in the `id_token`.
*/
$scopes = 'openid profile email';

Expand All @@ -95,7 +95,7 @@ $scopes = 'openid profile email';
$state = $crawler->randomString(40);

/**
* A verifier string which will be used to hash a code_challenge.
* A verifier string which will be used to create a code_challenge.
*/
$codeVerifier = $crawler->codeVerifier();

Expand Down Expand Up @@ -141,6 +141,9 @@ if ($state !== $receivedState) {
throw new Exception('States do not match!');
}

/**
* Now we can post the $_GET['code'] to request the tokens.
*/
$content = $crawler->httpRequest($tokensUrl, [
'grant_type' => 'authorization_code',
'client_id' => (string) $clientId,
Expand All @@ -158,15 +161,12 @@ if (!$content) {
throw new Exception('No valid json received');
}

$dump = [
'token_type' => $content['token_type'],
'expires_in' => $content['expires_in'],
'refresh_token' => $content['refresh_token'],
'access_token' => $crawler->parseJwt($content['access_token']),
];
$dump = array_merge($content, [
'parsed_access_token' => $crawler->parseJwt($content['access_token']),
]);

if (isset($content['id_token'])) {
$dump['id_token'] = $crawler->parseJwt($content['id_token']);
$dump['parsed_id_token'] = $crawler->parseJwt($content['id_token']);
}

print_r($dump);
2 changes: 1 addition & 1 deletion example/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
$clientRepository,
$accessTokenRepository,
$scopeRepository,
'file://' . $privateKeyPath,
$privateKeyPath,
$encryptionKey,
// [OpenIDConnect] Add the response_type
$responseType
Expand Down
File renamed without changes.

0 comments on commit a1b2b4f

Please sign in to comment.