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
For a complete reference of configuration options, see the [API Options](./API.md#options)
@@ -78,32 +78,28 @@ Depending on your use-case, any of the following supported grant types may be us
78
78
The [Authorization Code](https://oauth.net/2/grant-types/authorization-code/) grant type is used by confidential and public clients to exchange an authorization code for an access token. After the user returns to the client via the redirect URL, the application will get the authorization code from the URL and use it to request an access token.
79
79
80
80
```javascript
81
-
asyncfunctionrun() {
82
-
constclient=newAuthorizationCode(config);
81
+
constclient=newAuthorizationCode(config);
83
82
84
-
constauthorizationUri=client.authorizeURL({
85
-
redirect_uri:'http://localhost:3000/callback',
86
-
scope:'<scope>',
87
-
state:'<state>'
88
-
});
83
+
constauthorizationUri=client.authorizeURL({
84
+
redirect_uri:'http://localhost:3000/callback',
85
+
scope:'<scope>',
86
+
state:'<state>'
87
+
});
89
88
90
-
// Redirect example using Express (see http://expressjs.com/api.html#res.redirect)
91
-
res.redirect(authorizationUri);
89
+
// Redirect example using Express (see http://expressjs.com/api.html#res.redirect)
See the [API reference](./API.md#new-authorizationcodeoptions) for a complete reference of available options or any of our available examples at the [example folder](./example).
@@ -113,23 +109,19 @@ See the [API reference](./API.md#new-authorizationcodeoptions) for a complete re
113
109
The [Resource Owner Password Credentials](https://oauth.net/2/grant-types/password/) grant type is a way to exchange a user's credentials for an access token. Because the client application has to collect the user's password and send it to the authorization server, it is not recommended that this grant be used at all anymore.
See the [API reference](./API.md#new-resourceownerpasswordoptions) for a complete reference of available options.
@@ -139,21 +131,17 @@ See the [API reference](./API.md#new-resourceownerpasswordoptions) for a complet
139
131
The [Client Credentials](https://oauth.net/2/grant-types/client-credentials/) grant type is used by clients to obtain an access token outside of the context of a user. This is typically used by clients to access resources about themselves rather than to access a user's resources.
By the time we need to refresh the persistent access token, we can get back an [AccessToken](./API.md#accesstoken) instance by using the client's [.createToken](./API.md#createtokentoken--accesstoken) method.
let accessToken =client.createToken(JSON.parse(accessTokenJSONString));
190
170
```
191
171
192
172
Once we have determined the access token needs refreshing with the [.expired()](./API.md#expiredexpirationwindowseconds--boolean) method, we can finally refresh it with a [.refresh()](./API.md#await-refreshparams--accesstoken) method call.
The [.expired()](./API.md##expiredexpirationwindowseconds--boolean) helper is useful for knowing when a token has definitively expired. However, there is a common race condition when tokens are near expiring. If an OAuth 2.0 token is issued with a `expires_in` property (as opposed to an `expires_at` property), there can be discrepancies between the time the OAuth 2.0 server issues the access token and when it is received.
213
189
214
190
These come down to factors such as network and processing latency and can be worked around by preemptively refreshing the access token:
215
191
216
192
```javascript
217
-
asyncfunctionrun() {
218
-
constEXPIRATION_WINDOW_IN_SECONDS=300; // Window of time before the actual expiration to refresh the token
219
-
220
-
if (accessToken.expired(EXPIRATION_WINDOW_IN_SECONDS)) {
See the [API reference](./API.md#accesstoken) for a complete reference of available options.
@@ -272,18 +236,14 @@ See the [API reference](./API.md#accesstoken) for a complete reference of availa
272
236
Whenever a client or server error is produced, a [boom](https://github.com/hapijs/boom) error is thrown by the library. As such any [boom error property](https://hapi.dev/module/boom/api) is available, but the exact information may vary according to the type of error.
0 commit comments