UNPKG

1.29 kBJavaScriptView Raw
1"use strict";
2/*
3 * @adonisjs/auth
4 *
5 * (c) Harminder Virk <virk@adonisjs.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10Object.defineProperty(exports, "__esModule", { value: true });
11exports.OpaqueToken = void 0;
12/**
13 * Opaque token represents a persisted token generated for a given user
14 *
15 * Calling `opaqueToken.toJSON()` will give you an object, that you can send back
16 * as response to share the token with the client.
17 */
18class OpaqueToken {
19 constructor(name, // Name associated with the token
20 token, // The raw token value. Only available for the first time
21 user // The user for which the token is generated
22 ) {
23 this.name = name;
24 this.token = token;
25 this.user = user;
26 /**
27 * The type of the token. Always set to bearer
28 */
29 this.type = 'bearer';
30 }
31 /**
32 * Shareable version of the token
33 */
34 toJSON() {
35 return {
36 type: this.type,
37 token: this.token,
38 ...(this.expiresAt ? { expires_at: this.expiresAt.toISO() || undefined } : {}),
39 ...(this.expiresIn ? { expires_in: this.expiresIn } : {}),
40 };
41 }
42}
43exports.OpaqueToken = OpaqueToken;