-
Notifications
You must be signed in to change notification settings - Fork 5
JS SDK: document the new auth:refreshToken function #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5c6cd2b
[js sdk] document the new auth:refreshToken function
scottinet 0e1f760
[js sdk] explain that following auth:login the sdk will act as the au…
scottinet 42e6984
[sdk] add expiresIn default value
scottinet d6095ad
Merge remote-tracking branch 'origin/2-dev' into KZL-508/sdk-js-auth-…
scottinet 6b2b7fd
[sdk js] add a "since" tag to the new refreshToken function
scottinet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| --- | ||
| layout: sdk.html.hbs | ||
| title: refreshToken | ||
| description: Refresh an authentication token | ||
| --- | ||
|
|
||
| # refreshToken | ||
|
|
||
| {{{since "6.1.0"}}} | ||
|
|
||
| Refreshes a valid, non-expired authentication token. | ||
|
|
||
| If this action is successful, all further requests emitted by this SDK instance will use the refreshed authentication token. | ||
|
|
||
| ## Arguments | ||
|
|
||
| ```javascript | ||
| refreshToken ([options]) | ||
| ``` | ||
|
|
||
| <br/> | ||
|
|
||
| | Arguments | Type | Description | | ||
| |--------------|---------|-------------| | ||
| | `options` | <pre>object</pre> | Query options | | ||
|
|
||
|
|
||
| ### options | ||
|
|
||
| Additional query options | ||
|
|
||
| | Property | Type<br/>(default) | Description | | ||
| | -------------- | --------- | ------------- | | ||
| | `expiresIn` | <pre>string</pre> | Expiration time in [ms library](https://www.npmjs.com/package/ms) format. (e.g. `2h`) | | ||
| | `queuable` | <pre>boolean</pre><br/>(`true`)| If true, queues the request during downtime, until connected to Kuzzle again | | ||
|
|
||
| ### expiresIn | ||
|
|
||
| The default value for the `expiresIn` option is defined at server level, in Kuzzle's [configuration file]({{ site_base_map }}guide/1/essentials/configuration/). | ||
|
|
||
| ## Resolves | ||
|
|
||
| The `refreshToken` action resolves to a token object with the following properties: | ||
|
|
||
| | Property | Type | Description | | ||
| |--------------|---------|-------------| | ||
| | `_id` | <pre>string</pre> | User unique identifier ([kuid]({{ site_base_path }}guide/1/essentials/user-authentication/#kuzzle-user-identifier-kuid)) | | ||
| | `expiresAt` | <pre>number</pre> | Expiration timestamp in Epoch-millis format (UTC) | | ||
| | `jwt` | <pre>string</pre> | Authentication token | | ||
| | `ttl` | <pre>number</pre> | Time to live of the authentication token, in milliseconds | | ||
|
|
||
| ## Usage | ||
|
|
||
| [snippet=refreshToken] | ||
22 changes: 22 additions & 0 deletions
22
src/sdk-reference/js/6/auth/refresh-token/snippets/refreshToken.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| const credentials = { username: 'foo', password: 'bar' }; | ||
|
|
||
| try { | ||
| const jwt = await kuzzle.auth.login('local', credentials); | ||
|
|
||
| // Prints the encrypted authentication token | ||
| console.log(jwt); | ||
|
|
||
| // Note: to get a different token, you actually need to wait at least | ||
| // 1 second. Otherwise you do receive a refreshed token, but with the exact | ||
| // same caracteristics, as the key depends on the timestamp in Epoch format | ||
| await new Promise(resolve => setTimeout(resolve, 1000)); | ||
|
|
||
| // Prints: | ||
| // { _id: '<user kuid>', | ||
| // jwt: '<a different encrypted authentication token>' | ||
| // expiresAt: 1553185334220, | ||
| // ttl: 3600000 } | ||
| console.log(await kuzzle.auth.refreshToken()); | ||
| } catch (error) { | ||
| console.error(error.message); | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/sdk-reference/js/6/auth/refresh-token/snippets/refreshToken.test.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| name: auth#login | ||
| description: Authenticate a user | ||
| hooks: | ||
| before: curl -X POST kuzzle:7512/users/foo/_create -H "Content-Type:application/json" --data '{"content":{"profileIds":["default"]},"credentials":{"local":{"username":"foo","password":"bar"}}}' | ||
| after: curl -X DELETE kuzzle:7512/users/foo | ||
| template: default | ||
| expected: | ||
| - ^.*\..*$ | ||
| - "{ _id: 'foo'," | ||
| - ^\s*jwt: '.*\..*' | ||
| - ^\s*expiresAt: \d+ | ||
| - ^\s*ttl: \d+ } | ||
| sdk: js | ||
| version: 6 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the default value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't one per se, it's configured in the kuzzlerc file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can add a note or something to specify that so developers knows that a default value is configurable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to, because it meant I had to change all
logindocumentations for all SDK, as well as bring those documentation to today's format. 😑But you're right. So... thank you for noticing. I guess. 😑
It's done. 👍