@adonisjs/auth 9.3.2 → 9.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,6 +64,17 @@ export declare class AccessTokensGuard<UserProvider extends AccessTokensUserProv
64
64
  authenticate(): Promise<UserProvider[typeof PROVIDER_REAL_USER] & {
65
65
  currentAccessToken: AccessToken;
66
66
  }>;
67
+ /**
68
+ * Create a token for a user (sign in)
69
+ */
70
+ createToken(user: UserProvider[typeof PROVIDER_REAL_USER], abilities?: string[], options?: {
71
+ expiresIn?: string | number;
72
+ name?: string;
73
+ }): Promise<AccessToken>;
74
+ /**
75
+ * Invalidates the currently authenticated token (sign out)
76
+ */
77
+ invalidateToken(): Promise<boolean>;
67
78
  /**
68
79
  * Returns the Authorization header clients can use to authenticate
69
80
  * the request.
@@ -613,6 +613,19 @@ var AccessTokensGuard = class {
613
613
  });
614
614
  return this.user;
615
615
  }
616
+ /**
617
+ * Create a token for a user (sign in)
618
+ */
619
+ async createToken(user, abilities, options) {
620
+ return await this.#userProvider.createToken(user, abilities, options);
621
+ }
622
+ /**
623
+ * Invalidates the currently authenticated token (sign out)
624
+ */
625
+ async invalidateToken() {
626
+ const bearerToken = new Secret2(this.#getBearerToken());
627
+ return await this.#userProvider.invalidateToken(bearerToken);
628
+ }
616
629
  /**
617
630
  * Returns the Authorization header clients can use to authenticate
618
631
  * the request.
@@ -846,6 +859,18 @@ var DbAccessTokensProvider = class _DbAccessTokensProvider {
846
859
  }
847
860
  return accessToken;
848
861
  }
862
+ /**
863
+ * Invalidates a token identified by its publicly shared token
864
+ */
865
+ async invalidate(tokenValue) {
866
+ const decodedToken = AccessToken.decode(this.prefix, tokenValue.release());
867
+ if (!decodedToken) {
868
+ return false;
869
+ }
870
+ const db = await this.getDb();
871
+ const deleteCount = await db.query().from(this.table).where({ id: decodedToken.identifier, type: this.type }).del().exec();
872
+ return Boolean(deleteCount);
873
+ }
849
874
  };
850
875
 
851
876
  // modules/access_tokens_guard/user_providers/lucid.ts
@@ -913,6 +938,13 @@ var AccessTokensLucidUserProvider = class {
913
938
  const tokensProvider = await this.getTokensProvider();
914
939
  return tokensProvider.create(user, abilities, options);
915
940
  }
941
+ /**
942
+ * Invalidates a token identified by its publicly shared token
943
+ */
944
+ async invalidateToken(tokenValue) {
945
+ const tokensProvider = await this.getTokensProvider();
946
+ return tokensProvider.invalidate(tokenValue);
947
+ }
916
948
  /**
917
949
  * Finds a user by the user id
918
950
  */
@@ -73,4 +73,8 @@ export declare class DbAccessTokensProvider<TokenableModel extends LucidModel> i
73
73
  * inside the storage
74
74
  */
75
75
  verify(tokenValue: Secret<string>): Promise<AccessToken | null>;
76
+ /**
77
+ * Invalidates a token identified by its publicly shared token
78
+ */
79
+ invalidate(tokenValue: Secret<string>): Promise<boolean>;
76
80
  }
@@ -118,6 +118,10 @@ export interface AccessTokensProviderContract<Tokenable extends LucidModel> {
118
118
  * access token for it.
119
119
  */
120
120
  verify(tokenValue: Secret<string>): Promise<AccessToken | null>;
121
+ /**
122
+ * Invalidates a token identified by its publicly shared token
123
+ */
124
+ invalidate(tokenValue: Secret<string>): Promise<boolean>;
121
125
  }
122
126
  /**
123
127
  * A lucid model with a tokens provider to verify tokens during
@@ -167,6 +171,10 @@ export interface AccessTokensUserProviderContract<RealUser> {
167
171
  name?: string;
168
172
  expiresIn?: string | number;
169
173
  }): Promise<AccessToken>;
174
+ /**
175
+ * Invalidates a token identified by its publicly shared token.
176
+ */
177
+ invalidateToken(tokenValue: Secret<string>): Promise<boolean>;
170
178
  /**
171
179
  * Find a user by the user id.
172
180
  */
@@ -41,6 +41,10 @@ export declare class AccessTokensLucidUserProvider<TokenableProperty extends str
41
41
  name?: string;
42
42
  expiresIn?: string | number;
43
43
  }): Promise<AccessToken>;
44
+ /**
45
+ * Invalidates a token identified by its publicly shared token
46
+ */
47
+ invalidateToken(tokenValue: Secret<string>): Promise<boolean>;
44
48
  /**
45
49
  * Finds a user by the user id
46
50
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/auth",
3
3
  "description": "Official authentication provider for Adonis framework",
4
- "version": "9.3.2",
4
+ "version": "9.4.0",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },