File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,13 @@ This driver uses semantic versioning:
2222
2323## Added
2424
25+ - Added ` renewAuthToken ` method to ` Database ` ([ #784 ] ( https://github.com/arangodb/arangojs/issues/784 ) )
26+
27+ This method allows refreshing the authentication token passed to the
28+ ` useBearerAuth ` method or used by the ` login ` method. Note that ArangoDB
29+ will currently only return a new token if the token is going to expire
30+ in the next 150 seconds.
31+
2532- Added ` returnOld ` and ` mergeObjects ` to ` CollectionInsertOptions ` type
2633
2734 These options are only available when using ` overwriteMode ` .
Original file line number Diff line number Diff line change @@ -1793,6 +1793,34 @@ export class Database {
17931793 }
17941794 ) ;
17951795 }
1796+
1797+ /**
1798+ * Attempts to renew the authentication token passed to {@link Database#useBearerAuth}
1799+ * or returned and used by {@link Database#login}. If a new authentication
1800+ * token is issued, it will be used for future requests and returned.
1801+ *
1802+ * @example
1803+ * ```js
1804+ * const db = new Database();
1805+ * await db.login("admin", "hunter2");
1806+ * // ... later ...
1807+ * const newToken = await db.renewAuthToken();
1808+ * if (!newToken) // no new token issued
1809+ * ```
1810+ */
1811+ renewAuthToken ( ) : Promise < string | null > {
1812+ return this . request (
1813+ {
1814+ method : "POST" ,
1815+ path : "/_open/auth/renew" ,
1816+ } ,
1817+ ( res ) => {
1818+ if ( ! res . body . jwt ) return null ;
1819+ this . useBearerAuth ( res . body . jwt ) ;
1820+ return res . body . jwt ;
1821+ }
1822+ ) ;
1823+ }
17961824 //#endregion
17971825
17981826 //#region databases
You can’t perform that action at this time.
0 commit comments