Skip to content

Commit 7b987d6

Browse files
committed
Update token renewal documentation
1 parent 9367394 commit 7b987d6

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

docs/security/authentication.adoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ NOTE: RGT cookies can only be verified by the RESTHeart instance that issued the
107107

108108
This component is responsible for initiating a user's authenticated session by setting the authentication cookie.
109109

110-
Activates when a URL includes the query parameter `?set-auth-cookie` and a user is authenticated, setting a cookie populated with a token generated by the enabled Token Manager.
110+
Activates when the `/token/cookie` endpoint is called with valid credentials, setting a cookie populated with a token generated by the enabled Token Manager.
111111

112112
*Configuration*
113113

@@ -124,7 +124,9 @@ authCookieSetter:
124124
expires-ttl: 86400 # Defines the duration (in seconds, default 1 day) for which the cookie is valid
125125
```
126126

127-
When using JWT tokens, the cookie can be updated by calling `POST /token/cookie?renew`. The query parameter `renew` forces the `jwtTokenManager` to update the JWT.
127+
When using JWT tokens, the cookie can be updated by calling `POST /token/cookie?renew`. The query parameter `renew` forces the `jwtTokenManager` to generate a new JWT token.
128+
129+
You can also add the `?renew` query parameter to `GET /token` or `GET /token/cookie` requests to force token renewal.
128130

129131
===== authCookieHandler
130132

@@ -358,12 +360,10 @@ jwtTokenManager:
358360
issuer: restheart.com
359361
----
360362

361-
The query parameter renew-auth-token forces the token to be renewed.
363+
The query parameter `renew` forces the token to be renewed. Add it to `GET /token` or `GET /token/cookie` requests (e.g., `GET /token?renew`).
362364

363-
Generating a new token is a cryptographic operation,
364-
and it can have a significant performance overhead.
365-
It is responsibility of the client to renew the token using this query parameter
366-
when it is going to expiry somehow soon.
365+
Generating a new token is a cryptographic operation and can have a significant performance overhead.
366+
It is the responsibility of the client to renew the token using this query parameter when it is going to expire soon.
367367

368368

369369
=== Avoid browsers to open the login popup window

docs/security/how-clients-authenticate.adoc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,47 @@ fetch('[RESTHEART-URL]/mycollection', {
252252
.catch(error => console.error('Error:', error));
253253
----
254254

255+
===== Token Renewal
256+
257+
To renew an authentication token before it expires, add the `?renew` query parameter to `GET /token` or `GET /token/cookie` requests:
258+
259+
==== cURL
260+
[source,bash]
261+
----
262+
curl -i -X GET [RESTHEART-URL]/token?renew \
263+
-u [BASIC-AUTH]
264+
----
265+
266+
==== HTTPie
267+
[source,bash]
268+
----
269+
http GET [RESTHEART-URL]/token?renew \
270+
Authorization:"Basic [BASIC-AUTH]"
271+
----
272+
273+
==== JavaScript
274+
[source,javascript]
275+
----
276+
const username = 'your-username';
277+
const password = 'your-password';
278+
const credentials = btoa(`${username}:${password}`);
279+
280+
fetch('[RESTHEART-URL]/token?renew', {
281+
method: 'GET',
282+
headers: {
283+
'Authorization': `Basic ${credentials}`
284+
}
285+
})
286+
.then(response => response.json())
287+
.then(data => {
288+
console.log('New access token:', data.access_token);
289+
sessionStorage.setItem('auth_token', data.access_token);
290+
})
291+
.catch(error => console.error('Error:', error));
292+
----
293+
294+
NOTE: Generating a new token is a cryptographic operation and can have significant performance overhead. It is the responsibility of the client to renew the token using this query parameter when it is going to expire soon.
295+
255296
===== Cookie-Based Authentication
256297

257298
For browser-based applications, use the `/token/cookie` endpoint to set an HttpOnly cookie (more secure as the token isn't exposed to JavaScript):

0 commit comments

Comments
 (0)