Skip to content

Commit

Permalink
chore: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
hschoenenberger committed Dec 6, 2024
1 parent 6147b14 commit a957859
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ $prestaShopProvider = new \PrestaShop\OAuth2\Client\Provider\PrestaShop([
'clientSecret' => 'yourClientSecret', // The client password assigned to you by PrestaShop
'redirectUri' => 'yourClientRedirectUri', // The URL responding to the code flow implemented here
// Optional parameters
'cachedWellKnown' => new CachedFile(
__DIR__ . '/var/cache/openid-configuration.json', 15 * 60
),
'uiLocales' => ['fr-FR', 'en'],
'acrValues' => ['prompt:create'], // In that specific case we change the default prompt to the "register" page
]);
Expand Down Expand Up @@ -117,6 +120,9 @@ $prestaShopProvider = new \PrestaShop\OAuth2\Client\Provider\PrestaShop([
'redirectUri' => 'yourClientRedirectUri', // The URL responding to the code flow implemented here
'postLogoutCallbackUri' => 'yourLogoutCallbackUri', // Logout url whitelisted among the ones defined with your client
// Optional parameters
'cachedWellKnown' => new CachedFile(
__DIR__ . '/var/cache/openid-configuration.json', 15 * 60
),
'uiLocales' => ['fr-FR', 'en'],
'acrValues' => ['prompt:create'], // In that specific case we change the default prompt to the "register" page
]);
Expand All @@ -142,6 +148,45 @@ if (isset($_GET['oauth2Callback')) {
}
```

## Token Validation

```php
$prestaShopProvider = new \PrestaShop\OAuth2\Client\Provider\PrestaShop([
'clientId' => 'yourClientId', // The client ID assigned to you by PrestaShop
'clientSecret' => 'yourClientSecret', // The client password assigned to you by PrestaShop
'redirectUri' => 'yourClientRedirectUri', // The URL responding to the code flow implemented here
// Optional parameters
'cachedJwks' => new CachedFile(__DIR__ . '/var/cache/jwks.json'),
'cachedWellKnown' => new CachedFile(
__DIR__ . '/var/cache/openid-configuration.json', 15 * 60
),
'uiLocales' => ['fr-FR', 'en'],
'acrValues' => ['prompt:create'], // In that specific case we change the default prompt to the "register" page
]);

try {
// Only verifying a token
$prestaShopProvider->verifyToken($jwtString);
} catch (SignatureInvalidException) {
} catch (TokenExpiredException) {
} catch (TokenInvalidException) {
}

try {
// Verifying and checking required scope(s) and audience(s)
$prestaShopProvider->validateToken(
$jwtString,
['resource.read', 'resource.wrire'],
['https://an-audience']
);
} catch (SignatureInvalidException) {
} catch (TokenExpiredException) {
} catch (ScopeInvalidException) {
} catch (AudienceInvalidException) {
} catch (TokenInvalidException) {
}
```

## Testing

``` bash
Expand Down

0 comments on commit a957859

Please sign in to comment.