From cb56ceb562253ae65b074cb329b7c1a51bd5fc15 Mon Sep 17 00:00:00 2001 From: Ron van der Heijden Date: Tue, 16 Mar 2021 20:24:31 +0100 Subject: [PATCH 1/2] improved example --- example/get_tokens | 20 ++++++++++---------- example/index.php | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/example/get_tokens b/example/get_tokens index 4154bca..ecfd5f5 100755 --- a/example/get_tokens +++ b/example/get_tokens @@ -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'; @@ -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(); @@ -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, @@ -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); diff --git a/example/index.php b/example/index.php index 22ec4dc..d659725 100644 --- a/example/index.php +++ b/example/index.php @@ -57,7 +57,7 @@ $clientRepository, $accessTokenRepository, $scopeRepository, - 'file://' . $privateKeyPath, + $privateKeyPath, $encryptionKey, // [OpenIDConnect] Add the response_type $responseType From fee9d02b3061c9b8ce2b7e99410bfe839135cc00 Mon Sep 17 00:00:00 2001 From: Ron van der Heijden Date: Wed, 17 Mar 2021 09:24:46 +0100 Subject: [PATCH 2/2] added gitattributes file --- .gitattributes | 7 +++++++ .gitignore | 2 -- example/README.md | 2 +- phpunit.xml.dist => phpunit.xml | 0 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .gitattributes rename phpunit.xml.dist => phpunit.xml (100%) diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..7c02f8d --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/.gitignore b/.gitignore index 9caca6e..d2a1541 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,4 @@ vendor/ .phpunit.result.cache composer.lock tmp/ -dev/ .phplint-cache -phpd.log diff --git a/example/README.md b/example/README.md index 0a57637..f45c8ec 100644 --- a/example/README.md +++ b/example/README.md @@ -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 diff --git a/phpunit.xml.dist b/phpunit.xml similarity index 100% rename from phpunit.xml.dist rename to phpunit.xml