You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the `TokenRequestContext`, an instance of the `GraphServiceClient` requests access tokens and refresh tokens.
92
93
The tokens are stored by default in an in-memory cache so that future requests using the same instance of the `GraphServiceClient` can re-use the previously acquired tokens.
93
94
@@ -109,7 +110,7 @@ By default a `GraphServiceClient` instance caches access tokens in a built-in [`
109
110
However, to get the cached token that the SDK requests for a user/application you
110
111
can initialise an `InMemoryAccessTokenCache` or pass a custom implementation of the [`AccessTokenCache`](https://github.com/microsoft/kiota-authentication-phpleague-php/blob/dev/src/Cache/AccessTokenCache.php) interface interface and pass it as a parameter when initialising the `GraphServiceClient`. The two approaches are outlined below:
111
112
112
-
### Using an InMemoryAccessTokenCache instance:
113
+
### Using an InMemoryAccessTokenCache instance
113
114
114
115
```php
115
116
use Microsoft\Kiota\Authentication\Cache\InMemoryAccessTokenCache;
### Using a custom AccessTokenCache implementation:
147
+
### Using a custom AccessTokenCache implementation
147
148
148
149
A custom [`AccessTokenCache`](https://github.com/microsoft/kiota-authentication-phpleague-php/blob/dev/src/Cache/AccessTokenCache.php) interface implementation can also be provided. After the request, the SDK persists the token in the
149
150
custom cache via the `persistAccessToken()` method.
@@ -153,6 +154,8 @@ For `TokenRequestContexts` that do not require a signed in user (application per
153
154
**`{tenantId}-{clientId}`** and for those that require a signed in user (delegated permissions), the cache key will be
154
155
**`{tenantId}-{clientId}-{userId}`**.
155
156
157
+
Alternatively, you can override the default cache key
158
+
156
159
To retrieve the access token persisted to your custom cache for a particular user's/application's `TokenRequestContext`:
157
160
```php
158
161
@@ -172,7 +175,8 @@ This is also useful when re-using a previously retrieved access token for a sign
172
175
The SDK will check the cache for a valid token before considering requesting a new token. If the provided token is expired
173
176
and a refresh token is present, the access token will be refreshed and persisted to the cache. If no refresh token is provided, the SDK requests attempts to retrieve a new access token and persists it to the cache. In cases where a signed in user is present, e.g. authorization_code OAuth flows, the new token request will most likely fail because no valid `authorization_code` will be present meaning the user has to sign in again.
174
177
175
-
### Using the `InMemoryAccessTokenCache`:
178
+
### Using the `InMemoryAccessTokenCache`
179
+
176
180
The in-memory cache can be hydrated/initialised using the `TokenRequestContext` and a PHPLeague [`AccessToken`](https://github.com/thephpleague/oauth2-client/blob/master/src/Token/AccessToken.php) object for a user/application:
### Using a custom `AccessTokenCache` implementation`:
262
+
### Using a custom `AccessTokenCache` implementation`
259
263
260
264
The SDK retrieves cached tokens using a cache key/identifier on the `TokenRequestContext`. The cache key
261
265
on the `TokenRequestContext` is set using `setCacheKey()` which accepts an [`AccessToken`](https://github.com/thephpleague/oauth2-client/blob/master/src/Token/AccessToken.php) object.
@@ -269,13 +273,16 @@ For this scenario, the custom AccessTokenCache will need to be initialized in a
0 commit comments