Skip to content

Commit 2f5c6a9

Browse files
[documentation-improvements] Add api references links to access token usage documentation
1 parent e6188e5 commit 2f5c6a9

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
- [Resource Owner Password Credentials Grant](#resource-owner-password-credentials-grant)
2222
- [Client Credentials Grant](#client-credentials-grant)
2323
- [Access Token](#access-token)
24+
- [Refresh an access token](#refresh-an-access-token)
25+
- [Revoke an access or refresh token](#revoke-an-access-or-refresh-token)
2426
- [Errors](#errors)
2527
- [Debugging the module](#debugging-the-module)
2628
- [Contributing](#contributing)
@@ -153,23 +155,21 @@ See the [API reference](./API.md#new-clientcredentialsoptions) for a complete re
153155

154156
### Access Token
155157

156-
When a token expires we need to refresh it. Simple OAuth2 offers the AccessToken class that add a couple of useful methods to refresh the access token when it is expired.
158+
On completion of any [supported grant type](#supported-grant-types) an access token will be obtained. A list of supported operations can be found below.
159+
160+
#### Refresh an access token
161+
162+
When a token expires we need a mechanism to obtain a new access token. The [AccessToken](./API.md#accesstoken) methods can be used to perform the token refresh process.
157163

158164
```javascript
159165
async function run() {
160-
const tokenObject = {
161-
'access_token': '<access-token>',
162-
'refresh_token': '<refresh-token>',
163-
'expires_in': '7200'
164-
};
165-
166166
if (accessToken.expired()) {
167167
try {
168-
const params = {
168+
const refreshParams = {
169169
scope: '<scope>',
170170
};
171171

172-
accessToken = await accessToken.refresh(params);
172+
accessToken = await accessToken.refresh(refreshParams);
173173
} catch (error) {
174174
console.log('Error refreshing access token: ', error.message);
175175
}
@@ -199,7 +199,11 @@ async function run() {
199199
run();
200200
```
201201

202-
When you've done with the token or you want to log out, you can revoke the access and refresh tokens.
202+
See the [API reference](./API.md#accesstoken) for a complete reference of available options.
203+
204+
#### Revoke an access or refresh token
205+
206+
When you've done with the token or you want to log out, you can revoke both access and refresh tokens.
203207

204208
```javascript
205209
async function run() {
@@ -218,7 +222,6 @@ As a convenience method, you can also revoke both tokens in a single call:
218222

219223
```javascript
220224
async function run() {
221-
// Revoke both access and refresh tokens
222225
try {
223226
// Revokes both tokens, refresh token is only revoked if the access_token is properly revoked
224227
await accessToken.revokeAll();
@@ -230,26 +233,25 @@ async function run() {
230233
run();
231234
```
232235

233-
### Errors
234-
235-
Errors are returned when a 4xx or 5xx status code is received.
236+
See the [API reference](./API.md#accesstoken) for a complete reference of available options.
236237

237-
BoomError
238+
### Errors
238239

239-
As a standard [boom](https://github.com/hapijs/boom) error you can access any of the [boom error properties](https://hapi.dev/module/boom/api). The total amount of information varies according to the generated status code.
240+
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.
240241

241242
```javascript
242243
async function run() {
243-
const clientCredentials = new ClientCredentials(config);
244+
const client = new ClientCredentials(config);
244245

245246
try {
246-
await clientCredentials.getToken();
247+
await client.getToken();
247248
} catch(error) {
248249
console.log(error.output);
249250
}
250251
}
251252

252253
run();
254+
253255
// { statusCode: 401,
254256
// payload:
255257
// { statusCode: 401,

0 commit comments

Comments
 (0)