@adonisjs/auth 9.3.2 → 9.4.1
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.
- package/build/{chunk-U24HGFIR.js → chunk-2VRS2VHB.js} +1 -1
- package/build/{chunk-RKU6NS6C.js → chunk-JFTYQIKS.js} +1 -1
- package/build/index.js +2 -2
- package/build/modules/access_tokens_guard/guard.d.ts +11 -0
- package/build/modules/access_tokens_guard/main.js +36 -4
- package/build/modules/access_tokens_guard/token_providers/db.d.ts +4 -0
- package/build/modules/access_tokens_guard/types.d.ts +8 -0
- package/build/modules/access_tokens_guard/user_providers/lucid.d.ts +4 -0
- package/build/modules/session_guard/main.js +2 -2
- package/build/providers/auth_provider.js +2 -2
- package/build/src/errors.d.ts +2 -2
- package/build/src/plugins/japa/api_client.js +1 -1
- package/build/src/plugins/japa/browser_client.js +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -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.
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import "../../chunk-UXA4FHST.js";
|
|
5
5
|
|
|
6
6
|
// modules/access_tokens_guard/access_token.ts
|
|
7
|
-
import { createHash } from "
|
|
7
|
+
import { createHash } from "crypto";
|
|
8
8
|
import string from "@adonisjs/core/helpers/string";
|
|
9
9
|
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
10
10
|
import { Secret, base64, safeEqual } from "@adonisjs/core/helpers";
|
|
@@ -562,8 +562,8 @@ var AccessTokensGuard = class {
|
|
|
562
562
|
*/
|
|
563
563
|
#getBearerToken() {
|
|
564
564
|
const bearerToken = this.#ctx.request.header("authorization", "");
|
|
565
|
-
const [, token] = bearerToken.split("
|
|
566
|
-
if (!token) {
|
|
565
|
+
const [type, token] = bearerToken.split(" ");
|
|
566
|
+
if (!type || type.toLowerCase() !== "bearer" || !token) {
|
|
567
567
|
throw this.#authenticationFailed();
|
|
568
568
|
}
|
|
569
569
|
return token;
|
|
@@ -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.
|
|
@@ -644,7 +657,7 @@ var AccessTokensGuard = class {
|
|
|
644
657
|
};
|
|
645
658
|
|
|
646
659
|
// modules/access_tokens_guard/token_providers/db.ts
|
|
647
|
-
import { inspect } from "
|
|
660
|
+
import { inspect } from "util";
|
|
648
661
|
import { RuntimeException as RuntimeException2 } from "@adonisjs/core/exceptions";
|
|
649
662
|
var DbAccessTokensProvider = class _DbAccessTokensProvider {
|
|
650
663
|
constructor(options) {
|
|
@@ -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
|
*/
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import "../../chunk-UXA4FHST.js";
|
|
5
5
|
|
|
6
6
|
// modules/session_guard/remember_me_token.ts
|
|
7
|
-
import { createHash } from "
|
|
7
|
+
import { createHash } from "crypto";
|
|
8
8
|
import string from "@adonisjs/core/helpers/string";
|
|
9
9
|
import { Secret, base64, safeEqual } from "@adonisjs/core/helpers";
|
|
10
10
|
var RememberMeToken = class {
|
|
@@ -458,7 +458,7 @@ var SessionGuard = class {
|
|
|
458
458
|
};
|
|
459
459
|
|
|
460
460
|
// modules/session_guard/token_providers/db.ts
|
|
461
|
-
import { inspect } from "
|
|
461
|
+
import { inspect } from "util";
|
|
462
462
|
import { RuntimeException as RuntimeException2 } from "@adonisjs/core/exceptions";
|
|
463
463
|
var DbRememberMeTokensProvider = class _DbRememberMeTokensProvider {
|
|
464
464
|
constructor(options) {
|
package/build/src/errors.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export declare const E_UNAUTHORIZED_ACCESS: {
|
|
|
59
59
|
help?: string;
|
|
60
60
|
message?: string;
|
|
61
61
|
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
62
|
-
prepareStackTrace
|
|
62
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
63
63
|
stackTraceLimit: number;
|
|
64
64
|
};
|
|
65
65
|
/**
|
|
@@ -99,6 +99,6 @@ export declare const E_INVALID_CREDENTIALS: {
|
|
|
99
99
|
help?: string;
|
|
100
100
|
message?: string;
|
|
101
101
|
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
102
|
-
prepareStackTrace
|
|
102
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
103
103
|
stackTraceLimit: number;
|
|
104
104
|
};
|