@point3/logto-module 1.1.2 → 1.1.3
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/dist/client/__tests__/m2m-client.spec.d.ts +1 -0
- package/dist/client/__tests__/m2m-client.spec.js +55 -0
- package/dist/client/__tests__/m2m-client.spec.js.map +1 -0
- package/dist/client/__tests__/oauth-client.spec.d.ts +1 -0
- package/dist/client/__tests__/oauth-client.spec.js +40 -0
- package/dist/client/__tests__/oauth-client.spec.js.map +1 -0
- package/dist/client/config.d.ts +44 -0
- package/dist/client/config.js +16 -0
- package/dist/client/config.js.map +1 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +22 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/logto-login-session.d.ts +27 -0
- package/dist/client/logto-login-session.js +119 -0
- package/dist/client/logto-login-session.js.map +1 -0
- package/dist/client/m2m-client.d.ts +37 -0
- package/dist/client/m2m-client.js +196 -0
- package/dist/client/m2m-client.js.map +1 -0
- package/dist/client/oauth-client.d.ts +25 -0
- package/dist/client/oauth-client.js +129 -0
- package/dist/client/oauth-client.js.map +1 -0
- package/dist/client/types.d.ts +45 -0
- package/dist/client/types.js +37 -0
- package/dist/client/types.js.map +1 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.js +62 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/module.d.ts +27 -0
- package/dist/module.js +171 -0
- package/dist/module.js.map +1 -0
- package/dist/stateless/decorator.d.ts +7 -0
- package/dist/stateless/decorator.js +10 -0
- package/dist/stateless/decorator.js.map +1 -0
- package/dist/stateless/guard.d.ts +10 -0
- package/dist/stateless/guard.js +69 -0
- package/dist/stateless/guard.js.map +1 -0
- package/dist/stateless/guard.spec.d.ts +1 -0
- package/dist/stateless/guard.spec.js +210 -0
- package/dist/stateless/guard.spec.js.map +1 -0
- package/dist/stateless/index.d.ts +2 -0
- package/dist/stateless/index.js +19 -0
- package/dist/stateless/index.js.map +1 -0
- package/dist/token/access-token.d.ts +31 -0
- package/dist/token/access-token.js +19 -0
- package/dist/token/access-token.js.map +1 -0
- package/dist/token/index.d.ts +2 -0
- package/dist/token/index.js +19 -0
- package/dist/token/index.js.map +1 -0
- package/dist/token/verifier.d.ts +13 -0
- package/dist/token/verifier.js +56 -0
- package/dist/token/verifier.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
var OAuthClient_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.SignInType = exports.OAuthClient = exports.OAuthClientToken = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const axios_1 = __importDefault(require("axios"));
|
|
19
|
+
const config_1 = require("./config");
|
|
20
|
+
const point3_common_tool_1 = require("point3-common-tool");
|
|
21
|
+
const errors_1 = require("../errors");
|
|
22
|
+
const types_1 = require("./types");
|
|
23
|
+
const Gulid = point3_common_tool_1.p3Values.Gulid;
|
|
24
|
+
exports.OAuthClientToken = "OAuthClient";
|
|
25
|
+
let OAuthClient = OAuthClient_1 = class OAuthClient {
|
|
26
|
+
constructor(config, logger) {
|
|
27
|
+
this.config = config;
|
|
28
|
+
this.logger = logger;
|
|
29
|
+
this.logtoConfig = {
|
|
30
|
+
endpoint: config.endpoint,
|
|
31
|
+
appId: config.clientId,
|
|
32
|
+
appSecret: config.clientSecret,
|
|
33
|
+
resources: config.resources,
|
|
34
|
+
scopes: config.scopes,
|
|
35
|
+
prompt: config.prompt,
|
|
36
|
+
redirectUri: config.redirectUri,
|
|
37
|
+
grantType: config_1.GrantType.AuthorizationCode,
|
|
38
|
+
};
|
|
39
|
+
this.logtoRestTemplate = new types_1.LogtoOAuthRESTTemplate(logger, this.logtoConfig.endpoint);
|
|
40
|
+
this.logtoRestTemplate.setBasic(this.logtoConfig.appId, this.logtoConfig.appSecret);
|
|
41
|
+
}
|
|
42
|
+
getSignInURI(signInType) {
|
|
43
|
+
try {
|
|
44
|
+
let uri;
|
|
45
|
+
if (signInType === SignInType.Dashboard) {
|
|
46
|
+
if (this.config.dashboardSignInUri) {
|
|
47
|
+
uri = new URL(`${this.config.dashboardSignInUri}/auth`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.logger.warn("대시보드 로그인 URI 설정을 찾을 수 없어 기본 URI를 사용합니다.", this.constructor.name);
|
|
51
|
+
uri = new URL(`${this.config.signInUri}/auth`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
uri = new URL(`${this.config.signInUri}/auth`);
|
|
56
|
+
}
|
|
57
|
+
const state = Gulid.create(OAuthClient_1.prefix);
|
|
58
|
+
uri.searchParams.set("redirect_uri", this.logtoConfig.redirectUri);
|
|
59
|
+
uri.searchParams.set("response_type", "code");
|
|
60
|
+
uri.searchParams.set("scope", this.logtoConfig.scopes.join(" "));
|
|
61
|
+
uri.searchParams.set("prompt", this.logtoConfig.prompt);
|
|
62
|
+
uri.searchParams.set("client_id", this.logtoConfig.appId);
|
|
63
|
+
uri.searchParams.set("resource", this.logtoConfig.resources.join(" "));
|
|
64
|
+
uri.searchParams.set("state", state.toString());
|
|
65
|
+
return { uri: uri.toString(), state: state.toString() };
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw new errors_1.SignInUriGenerationError(signInType);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async getSignOutURI() {
|
|
72
|
+
try {
|
|
73
|
+
const uri = new URL(`${this.config.signInUri}/session/end`);
|
|
74
|
+
uri.searchParams.set("redirect_uri", this.logtoConfig.redirectUri);
|
|
75
|
+
uri.searchParams.set("client_id", this.logtoConfig.appId);
|
|
76
|
+
return uri.toString();
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw new errors_1.SignOutUriGenerationError();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async fetchTokenByAuthorizationCode(code) {
|
|
83
|
+
try {
|
|
84
|
+
const parameters = new URLSearchParams();
|
|
85
|
+
parameters.set("code", code);
|
|
86
|
+
parameters.set("grant_type", this.logtoConfig.grantType);
|
|
87
|
+
parameters.set("redirect_uri", this.logtoConfig.redirectUri);
|
|
88
|
+
parameters.set("resource", this.logtoConfig.resources.join(" "));
|
|
89
|
+
parameters.set("scope", this.logtoConfig.scopes.join(" "));
|
|
90
|
+
const response = await this.logtoRestTemplate.post(`${this.logtoConfig.endpoint}/token`, parameters.toString());
|
|
91
|
+
return {
|
|
92
|
+
accessToken: response.data.access_token,
|
|
93
|
+
idToken: response.data.id_token,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
throw new errors_1.AuthorizationCodeTokenFetchError(code);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async revokeToken(token) {
|
|
101
|
+
try {
|
|
102
|
+
const response = await axios_1.default.post(`${this.logtoConfig.endpoint}/token/revoke`, new URLSearchParams({
|
|
103
|
+
token: token,
|
|
104
|
+
client_id: this.logtoConfig.appId,
|
|
105
|
+
}).toString(), {
|
|
106
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
107
|
+
});
|
|
108
|
+
if (response.status === 200)
|
|
109
|
+
return;
|
|
110
|
+
throw new errors_1.TokenRevocationFailedError();
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
throw new errors_1.TokenRevocationFailedError();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
exports.OAuthClient = OAuthClient;
|
|
118
|
+
OAuthClient.prefix = "signin";
|
|
119
|
+
exports.OAuthClient = OAuthClient = OAuthClient_1 = __decorate([
|
|
120
|
+
(0, common_1.Global)(),
|
|
121
|
+
(0, common_1.Injectable)(),
|
|
122
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
123
|
+
], OAuthClient);
|
|
124
|
+
var SignInType;
|
|
125
|
+
(function (SignInType) {
|
|
126
|
+
SignInType["Admin"] = "admin";
|
|
127
|
+
SignInType["Dashboard"] = "dashboard";
|
|
128
|
+
})(SignInType || (exports.SignInType = SignInType = {}));
|
|
129
|
+
//# sourceMappingURL=oauth-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-client.js","sourceRoot":"","sources":["../../client/oauth-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAmE;AACnE,kDAA6C;AAC7C,qCAAoE;AACpE,2DAA4D;AAC5D,sCAKmB;AACnB,mCAA0E;AAE1E,MAAM,KAAK,GAAG,6BAAQ,CAAC,KAAK,CAAC;AAGhB,QAAA,gBAAgB,GAAG,aAAa,CAAC;AAwBvC,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAapB,YACqB,MAAwB,EACxB,MAAqB;QADrB,WAAM,GAAN,MAAM,CAAkB;QACxB,WAA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IAMM,KAAK,CAAC,WAAW,CAAC,KAAa;QAClC,IAAI,CAAC;YACD,MAAM,QAAQ,GAAkB,MAAM,eAAK,CAAC,IAAI,CAC5C,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,eAAe,EAC3C,IAAI,eAAe,CAAC;gBAChB,KAAK,EAAE,KAAK;gBACZ,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,KAAM;aACrC,CAAC,CAAC,QAAQ,EAAE,EACb;gBACI,OAAO,EAAE,EAAE,cAAc,EAAE,mCAAmC,EAAE;aACnE,CACJ,CAAC;YAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;gBAAE,OAAO;YAEpC,MAAM,IAAI,mCAA0B,EAAE,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,mCAA0B,EAAE,CAAC;QAC3C,CAAC;IACL,CAAC;;AA3JQ,kCAAW;AAMJ,kBAAM,GAAW,QAAQ,AAAnB,CAAoB;sBANjC,WAAW;IAFvB,IAAA,eAAM,GAAE;IACR,IAAA,mBAAU,GAAE;;GACA,WAAW,CA4JvB;AAOD,IAAY,UAGX;AAHD,WAAY,UAAU;IAClB,6BAAe,CAAA;IACf,qCAAuB,CAAA;AAC3B,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { axiosAdapter, p3Values } from 'point3-common-tool';
|
|
2
|
+
export declare class LogtoUserAlreadyExistsError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare enum LogtoPasswordAlgorithm {
|
|
6
|
+
Argon2i = "Argon2i",
|
|
7
|
+
Argon2id = "Argon2id",
|
|
8
|
+
Argon2d = "Argon2d",
|
|
9
|
+
SHA1 = "SHA1",
|
|
10
|
+
Bcrypt = "Bcrypt"
|
|
11
|
+
}
|
|
12
|
+
export type LogtoUser = {
|
|
13
|
+
username: string;
|
|
14
|
+
primaryPhone?: string;
|
|
15
|
+
primaryEmail: string;
|
|
16
|
+
password: string;
|
|
17
|
+
passwordAlgorithm?: LogtoPasswordAlgorithm;
|
|
18
|
+
name: string;
|
|
19
|
+
avatar?: string;
|
|
20
|
+
customData?: Record<string, any>;
|
|
21
|
+
};
|
|
22
|
+
export type LogtoUserResponse = {
|
|
23
|
+
id: string;
|
|
24
|
+
} & LogtoUser;
|
|
25
|
+
export type LogtoRole = {
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
type: string;
|
|
29
|
+
isDefault?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type LogtoRoleResponse = {
|
|
32
|
+
id: string;
|
|
33
|
+
} & LogtoRole;
|
|
34
|
+
export declare class VerificationMethodType {
|
|
35
|
+
static phone: typeof p3Values.PhoneNumber;
|
|
36
|
+
static email: typeof p3Values.Email;
|
|
37
|
+
}
|
|
38
|
+
export declare class SMSVerificationResponse {
|
|
39
|
+
verificationId: string;
|
|
40
|
+
expiresAt: string;
|
|
41
|
+
constructor(verificationId: string, expiresAt: string);
|
|
42
|
+
}
|
|
43
|
+
export declare class LogtoOAuthRESTTemplate extends axiosAdapter.RESTTemplate {
|
|
44
|
+
}
|
|
45
|
+
export declare const LogtoLoggerServiceToken: unique symbol;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogtoLoggerServiceToken = exports.LogtoOAuthRESTTemplate = exports.SMSVerificationResponse = exports.VerificationMethodType = exports.LogtoPasswordAlgorithm = exports.LogtoUserAlreadyExistsError = void 0;
|
|
4
|
+
const point3_common_tool_1 = require("point3-common-tool");
|
|
5
|
+
class LogtoUserAlreadyExistsError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'UserAlreadyExistsError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.LogtoUserAlreadyExistsError = LogtoUserAlreadyExistsError;
|
|
12
|
+
var LogtoPasswordAlgorithm;
|
|
13
|
+
(function (LogtoPasswordAlgorithm) {
|
|
14
|
+
LogtoPasswordAlgorithm["Argon2i"] = "Argon2i";
|
|
15
|
+
LogtoPasswordAlgorithm["Argon2id"] = "Argon2id";
|
|
16
|
+
LogtoPasswordAlgorithm["Argon2d"] = "Argon2d";
|
|
17
|
+
LogtoPasswordAlgorithm["SHA1"] = "SHA1";
|
|
18
|
+
LogtoPasswordAlgorithm["Bcrypt"] = "Bcrypt";
|
|
19
|
+
})(LogtoPasswordAlgorithm || (exports.LogtoPasswordAlgorithm = LogtoPasswordAlgorithm = {}));
|
|
20
|
+
class VerificationMethodType {
|
|
21
|
+
}
|
|
22
|
+
exports.VerificationMethodType = VerificationMethodType;
|
|
23
|
+
VerificationMethodType.phone = point3_common_tool_1.p3Values.PhoneNumber;
|
|
24
|
+
VerificationMethodType.email = point3_common_tool_1.p3Values.Email;
|
|
25
|
+
class SMSVerificationResponse {
|
|
26
|
+
constructor(verificationId, expiresAt) {
|
|
27
|
+
this.verificationId = verificationId;
|
|
28
|
+
this.expiresAt = expiresAt;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.SMSVerificationResponse = SMSVerificationResponse;
|
|
32
|
+
class LogtoOAuthRESTTemplate extends point3_common_tool_1.axiosAdapter.RESTTemplate {
|
|
33
|
+
}
|
|
34
|
+
exports.LogtoOAuthRESTTemplate = LogtoOAuthRESTTemplate;
|
|
35
|
+
;
|
|
36
|
+
exports.LogtoLoggerServiceToken = Symbol.for("LogtoLoggerService");
|
|
37
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../client/types.ts"],"names":[],"mappings":";;;AAAA,2DAA4D;AAQ5D,MAAa,2BAA4B,SAAQ,KAAK;IAClD,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACzC,CAAC;CACJ;AALD,kEAKC;AAUD,IAAY,sBAMX;AAND,WAAY,sBAAsB;IAC9B,6CAAmB,CAAA;IACnB,+CAAqB,CAAA;IACrB,6CAAmB,CAAA;IACnB,uCAAa,CAAA;IACb,2CAAiB,CAAA;AACrB,CAAC,EANW,sBAAsB,sCAAtB,sBAAsB,QAMjC;AAuED,MAAa,sBAAsB;;AAAnC,wDAGC;AAFU,4BAAK,GAAG,6BAAQ,CAAC,WAAW,CAAC;AAC7B,4BAAK,GAAG,6BAAQ,CAAC,KAAK,CAAC;AAUlC,MAAa,uBAAuB;IAIhC,YAAY,cAAsB,EAAE,SAAiB;QACjD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;CACJ;AARD,0DAQC;AAQD,MAAa,sBAAuB,SAAQ,iCAAY,CAAC,YAAY;CAAG;AAAxE,wDAAwE;AAAA,CAAC;AAO5D,QAAA,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare class LogtoError extends Error {
|
|
2
|
+
constructor(e: string | Error);
|
|
3
|
+
}
|
|
4
|
+
export declare class UserMissingRequiredFieldsError extends LogtoError {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
export declare class UserNotFoundError extends LogtoError {
|
|
8
|
+
constructor(email: string, phone: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class MultipleUsersFoundError extends LogtoError {
|
|
11
|
+
constructor(email: string, phone: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class TokenRevocationFailedError extends LogtoError {
|
|
14
|
+
constructor();
|
|
15
|
+
}
|
|
16
|
+
export declare class AuthorizationCodeTokenFetchError extends LogtoError {
|
|
17
|
+
constructor(code: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class SignInUriGenerationError extends LogtoError {
|
|
20
|
+
constructor(signInType: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class SignOutUriGenerationError extends LogtoError {
|
|
23
|
+
constructor();
|
|
24
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignOutUriGenerationError = exports.SignInUriGenerationError = exports.AuthorizationCodeTokenFetchError = exports.TokenRevocationFailedError = exports.MultipleUsersFoundError = exports.UserNotFoundError = exports.UserMissingRequiredFieldsError = exports.LogtoError = void 0;
|
|
4
|
+
class LogtoError extends Error {
|
|
5
|
+
constructor(e) {
|
|
6
|
+
super(typeof e === 'string' ? e : e.message);
|
|
7
|
+
Error.captureStackTrace(this, this.constructor);
|
|
8
|
+
this.name = 'LogtoError';
|
|
9
|
+
this.message = typeof e == 'string' ? e : e.message || '';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.LogtoError = LogtoError;
|
|
13
|
+
class UserMissingRequiredFieldsError extends LogtoError {
|
|
14
|
+
constructor() {
|
|
15
|
+
super('사용자 생성에 필요한 필수 정보가 누락되었습니다.');
|
|
16
|
+
this.name = "UserMissingRequiredFieldsError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.UserMissingRequiredFieldsError = UserMissingRequiredFieldsError;
|
|
20
|
+
class UserNotFoundError extends LogtoError {
|
|
21
|
+
constructor(email, phone) {
|
|
22
|
+
super(`이메일: ${email}, 전화번호: ${phone}로 사용자를 찾을 수 없습니다.`);
|
|
23
|
+
this.name = "UserNotFoundError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.UserNotFoundError = UserNotFoundError;
|
|
27
|
+
class MultipleUsersFoundError extends LogtoError {
|
|
28
|
+
constructor(email, phone) {
|
|
29
|
+
super(`이메일: ${email}, 전화번호: ${phone}로 여러 사용자가 발견되었습니다.`);
|
|
30
|
+
this.name = "MultipleUsersFoundError";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.MultipleUsersFoundError = MultipleUsersFoundError;
|
|
34
|
+
class TokenRevocationFailedError extends LogtoError {
|
|
35
|
+
constructor() {
|
|
36
|
+
super('토큰 해지에 실패했습니다.');
|
|
37
|
+
this.name = "TokenRevocationFailedError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.TokenRevocationFailedError = TokenRevocationFailedError;
|
|
41
|
+
class AuthorizationCodeTokenFetchError extends LogtoError {
|
|
42
|
+
constructor(code) {
|
|
43
|
+
super(`인증 코드를 사용한 토큰 발급에 실패했습니다. 코드: ${code}`);
|
|
44
|
+
this.name = "AuthorizationCodeTokenFetchError";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.AuthorizationCodeTokenFetchError = AuthorizationCodeTokenFetchError;
|
|
48
|
+
class SignInUriGenerationError extends LogtoError {
|
|
49
|
+
constructor(signInType) {
|
|
50
|
+
super(`로그인 URI 생성에 실패했습니다. 타입: ${signInType}`);
|
|
51
|
+
this.name = "SignInUriGenerationError";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.SignInUriGenerationError = SignInUriGenerationError;
|
|
55
|
+
class SignOutUriGenerationError extends LogtoError {
|
|
56
|
+
constructor() {
|
|
57
|
+
super('로그아웃 URI 생성에 실패했습니다.');
|
|
58
|
+
this.name = "SignOutUriGenerationError";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.SignOutUriGenerationError = SignOutUriGenerationError;
|
|
62
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,UAAW,SAAQ,KAAK;IACjC,YAAY,CAAiB;QACzB,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CA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wBAAyB,SAAQ,UAAU;IACpD,YAAY,UAAkB;QAC1B,KAAK,CAAC,2BAA2B,UAAU,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IAC3C,CAAC;CACJ;AALD,4DAKC;AAED,MAAa,yBAA0B,SAAQ,UAAU;IACrD;QACI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC5C,CAAC;CACJ;AALD,8DAKC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.module = exports.stateless = exports.client = exports.token = void 0;
|
|
37
|
+
exports.token = __importStar(require("./token"));
|
|
38
|
+
exports.client = __importStar(require("./client"));
|
|
39
|
+
exports.stateless = __importStar(require("./stateless"));
|
|
40
|
+
exports.module = __importStar(require("./module"));
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAiC;AACjC,mDAAmC;AACnC,yDAAyC;AACzC,mDAAmC"}
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DynamicModule, Type } from '@nestjs/common';
|
|
2
|
+
export declare const LOGTO_MODULE_OPTIONS: unique symbol;
|
|
3
|
+
export interface LogtoLoggerOptions {
|
|
4
|
+
module?: Type<any>;
|
|
5
|
+
token: Symbol | string;
|
|
6
|
+
}
|
|
7
|
+
export interface LogtoModuleOptions {
|
|
8
|
+
global?: boolean;
|
|
9
|
+
enableClient?: boolean;
|
|
10
|
+
logger: LogtoLoggerOptions & {
|
|
11
|
+
module: Type<any>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface LogtoModuleFactoryOptions {
|
|
15
|
+
enableClient?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface LogtoModuleAsyncOptions {
|
|
18
|
+
global?: boolean;
|
|
19
|
+
imports?: Type<any>[];
|
|
20
|
+
loggerToken: Symbol | string;
|
|
21
|
+
useFactory: (...args: any[]) => LogtoModuleFactoryOptions | Promise<LogtoModuleFactoryOptions>;
|
|
22
|
+
inject?: any[];
|
|
23
|
+
}
|
|
24
|
+
export declare class LogtoModule {
|
|
25
|
+
static forRoot(options: LogtoModuleOptions): DynamicModule;
|
|
26
|
+
static forRootAsync(options: LogtoModuleAsyncOptions): DynamicModule;
|
|
27
|
+
}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogtoModule = exports.LOGTO_MODULE_OPTIONS = void 0;
|
|
4
|
+
const config_1 = require("@nestjs/config");
|
|
5
|
+
const client_1 = require("./client");
|
|
6
|
+
const token_1 = require("./token");
|
|
7
|
+
const stateless_1 = require("./stateless");
|
|
8
|
+
exports.LOGTO_MODULE_OPTIONS = Symbol('LOGTO_MODULE_OPTIONS');
|
|
9
|
+
class LogtoModule {
|
|
10
|
+
static forRoot(options) {
|
|
11
|
+
const { global = false, enableClient = false, logger } = options;
|
|
12
|
+
const baseProviders = [
|
|
13
|
+
{
|
|
14
|
+
provide: client_1.LogtoLoggerServiceToken,
|
|
15
|
+
useExisting: logger.token,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
provide: token_1.LogtoTokenVerifierToken,
|
|
19
|
+
useFactory: (configService) => {
|
|
20
|
+
return new token_1.LogtoTokenVerifier({
|
|
21
|
+
jwksUri: configService.getOrThrow('LOGTO_JWKS_URI'),
|
|
22
|
+
issuer: configService.getOrThrow('LOGTO_AUTH_ISSUER'),
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
inject: [config_1.ConfigService],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
provide: stateless_1.LogtoTokenGuardToken,
|
|
29
|
+
useClass: stateless_1.LogtoTokenGuard,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
const clientProviders = enableClient
|
|
33
|
+
? [
|
|
34
|
+
{
|
|
35
|
+
provide: client_1.OAuthClientToken,
|
|
36
|
+
useFactory: (configService, loggerService) => {
|
|
37
|
+
return new client_1.OAuthClient({
|
|
38
|
+
endpoint: configService.getOrThrow('LOGTO_AUTH_ENDPOINT'),
|
|
39
|
+
clientId: configService.getOrThrow('LOGTO_CLIENT_ID'),
|
|
40
|
+
clientSecret: configService.getOrThrow('LOGTO_CLIENT_SECRET'),
|
|
41
|
+
resources: [configService.getOrThrow('LOGTO_RESOURCES')],
|
|
42
|
+
scopes: configService.getOrThrow('LOGTO_SCOPES').split(','),
|
|
43
|
+
prompt: configService.getOrThrow('LOGTO_PROMPT'),
|
|
44
|
+
redirectUri: configService.getOrThrow('LOGTO_REDIRECT_URI'),
|
|
45
|
+
signInUri: configService.getOrThrow('LOGTO_SIGN_IN_URI'),
|
|
46
|
+
dashboardSignInUri: configService.getOrThrow('LOGTO_DASHBOARD_SIGN_IN_URI'),
|
|
47
|
+
}, loggerService);
|
|
48
|
+
},
|
|
49
|
+
inject: [config_1.ConfigService, client_1.LogtoLoggerServiceToken],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
provide: client_1.LogtoLoginSessionToken,
|
|
53
|
+
useFactory: (configService, loggerService, oauthClient) => {
|
|
54
|
+
return new client_1.LogtoLoginSession(configService.getOrThrow('LOGTO_M2M_API_URL'), loggerService, oauthClient);
|
|
55
|
+
},
|
|
56
|
+
inject: [config_1.ConfigService, client_1.LogtoLoggerServiceToken, client_1.OAuthClientToken],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
provide: client_1.LogtoM2MClientToken,
|
|
60
|
+
useFactory: (configService, tokenVerifier, loggerService) => {
|
|
61
|
+
return new client_1.LogtoM2MClient({
|
|
62
|
+
endpoint: configService.getOrThrow('LOGTO_AUTH_ENDPOINT'),
|
|
63
|
+
clientId: configService.getOrThrow('LOGTO_M2M_CLIENT_ID'),
|
|
64
|
+
clientSecret: configService.getOrThrow('LOGTO_M2M_CLIENT_SECRET'),
|
|
65
|
+
resource: configService.getOrThrow('LOGTO_M2M_RESOURCE'),
|
|
66
|
+
apiUrl: configService.getOrThrow('LOGTO_M2M_API_URL'),
|
|
67
|
+
scopes: ['all'],
|
|
68
|
+
}, tokenVerifier, loggerService);
|
|
69
|
+
},
|
|
70
|
+
inject: [config_1.ConfigService, token_1.LogtoTokenVerifierToken, client_1.LogtoLoggerServiceToken],
|
|
71
|
+
},
|
|
72
|
+
]
|
|
73
|
+
: [];
|
|
74
|
+
const providers = [...baseProviders, ...clientProviders];
|
|
75
|
+
return {
|
|
76
|
+
module: LogtoModule,
|
|
77
|
+
global,
|
|
78
|
+
imports: [config_1.ConfigModule, logger.module],
|
|
79
|
+
providers,
|
|
80
|
+
exports: providers,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
static forRootAsync(options) {
|
|
84
|
+
const { global = false, imports = [], loggerToken, useFactory, inject = [] } = options;
|
|
85
|
+
const asyncOptionsProvider = {
|
|
86
|
+
provide: exports.LOGTO_MODULE_OPTIONS,
|
|
87
|
+
useFactory,
|
|
88
|
+
inject,
|
|
89
|
+
};
|
|
90
|
+
const baseProviders = [
|
|
91
|
+
asyncOptionsProvider,
|
|
92
|
+
{
|
|
93
|
+
provide: client_1.LogtoLoggerServiceToken,
|
|
94
|
+
useExisting: loggerToken,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
provide: token_1.LogtoTokenVerifierToken,
|
|
98
|
+
useFactory: (configService) => {
|
|
99
|
+
return new token_1.LogtoTokenVerifier({
|
|
100
|
+
jwksUri: configService.getOrThrow('LOGTO_JWKS_URI'),
|
|
101
|
+
issuer: configService.getOrThrow('LOGTO_AUTH_ISSUER'),
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
inject: [config_1.ConfigService],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
provide: stateless_1.LogtoTokenGuardToken,
|
|
108
|
+
useClass: stateless_1.LogtoTokenGuard,
|
|
109
|
+
},
|
|
110
|
+
];
|
|
111
|
+
const clientProviders = [
|
|
112
|
+
{
|
|
113
|
+
provide: client_1.OAuthClientToken,
|
|
114
|
+
useFactory: (opts, configService, loggerService) => {
|
|
115
|
+
if (opts.enableClient) {
|
|
116
|
+
return new client_1.OAuthClient({
|
|
117
|
+
endpoint: configService.getOrThrow('LOGTO_AUTH_ENDPOINT'),
|
|
118
|
+
clientId: configService.getOrThrow('LOGTO_CLIENT_ID'),
|
|
119
|
+
clientSecret: configService.getOrThrow('LOGTO_CLIENT_SECRET'),
|
|
120
|
+
resources: [configService.getOrThrow('LOGTO_RESOURCES')],
|
|
121
|
+
scopes: configService.getOrThrow('LOGTO_SCOPES').split(','),
|
|
122
|
+
prompt: configService.getOrThrow('LOGTO_PROMPT'),
|
|
123
|
+
redirectUri: configService.getOrThrow('LOGTO_REDIRECT_URI'),
|
|
124
|
+
signInUri: configService.getOrThrow('LOGTO_SIGN_IN_URI'),
|
|
125
|
+
dashboardSignInUri: configService.getOrThrow('LOGTO_DASHBOARD_SIGN_IN_URI'),
|
|
126
|
+
}, loggerService);
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
},
|
|
130
|
+
inject: [exports.LOGTO_MODULE_OPTIONS, config_1.ConfigService, client_1.LogtoLoggerServiceToken],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
provide: client_1.LogtoLoginSessionToken,
|
|
134
|
+
useFactory: (opts, configService, loggerService, oauthClient) => {
|
|
135
|
+
if (opts.enableClient) {
|
|
136
|
+
return new client_1.LogtoLoginSession(configService.getOrThrow('LOGTO_M2M_API_URL'), loggerService, oauthClient);
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
},
|
|
140
|
+
inject: [exports.LOGTO_MODULE_OPTIONS, config_1.ConfigService, client_1.LogtoLoggerServiceToken, client_1.OAuthClientToken],
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
provide: client_1.LogtoM2MClientToken,
|
|
144
|
+
useFactory: (opts, configService, tokenVerifier, loggerService) => {
|
|
145
|
+
if (opts.enableClient) {
|
|
146
|
+
return new client_1.LogtoM2MClient({
|
|
147
|
+
endpoint: configService.getOrThrow('LOGTO_AUTH_ENDPOINT'),
|
|
148
|
+
clientId: configService.getOrThrow('LOGTO_M2M_CLIENT_ID'),
|
|
149
|
+
clientSecret: configService.getOrThrow('LOGTO_M2M_CLIENT_SECRET'),
|
|
150
|
+
resource: configService.getOrThrow('LOGTO_M2M_RESOURCE'),
|
|
151
|
+
apiUrl: configService.getOrThrow('LOGTO_M2M_API_URL'),
|
|
152
|
+
scopes: ['all'],
|
|
153
|
+
}, tokenVerifier, loggerService);
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
},
|
|
157
|
+
inject: [exports.LOGTO_MODULE_OPTIONS, config_1.ConfigService, token_1.LogtoTokenVerifierToken, client_1.LogtoLoggerServiceToken],
|
|
158
|
+
},
|
|
159
|
+
];
|
|
160
|
+
const providers = [...baseProviders, ...clientProviders];
|
|
161
|
+
return {
|
|
162
|
+
module: LogtoModule,
|
|
163
|
+
global,
|
|
164
|
+
imports: [config_1.ConfigModule, ...imports],
|
|
165
|
+
providers,
|
|
166
|
+
exports: providers,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.LogtoModule = LogtoModule;
|
|
171
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../module.ts"],"names":[],"mappings":";;;AACA,2CAA6D;AAC7D,qCASkB;AAClB,mCAAsE;AACtE,2CAAoE;AAGvD,QAAA,oBAAoB,GAAG,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAsDnE,MAAa,WAAW;IAwBpB,MAAM,CAAC,OAAO,CAAC,OAA2B;QACtC,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,YAAY,GAAG,KAAK,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AAC,UAAU,CAAS,yBAAyB,CAAC;4BACzE,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAS,oBAAoB,CAAC;4BAChE,MAAM,EAAE,aAAa,CAAC,UAAU,CAAS,mBAAmB,CAAC;4BAC7D,MAAM,EAAE,CAAC,KAAK,CAAC;yBAClB,EACD,aAAa,EACb,aAAa,CAChB,CAAC;oBACN,CAAC;oBACD,OAAO,IAAI,CAAC;gBAChB,CAAC;gBACD,MAAM,EAAE,CAAC,4BAAoB,EAAE,sBAAa,EAAE,+BAAuB,EAAE,gCAAuB,CAAC;aAClG;SACJ,CAAC;QAEF,MAAM,SAAS,GAAG,CAAC,GAAG,aAAa,EAAE,GAAG,eAAe,CAAC,CAAC;QAEzD,OAAO;YACH,MAAM,EAAE,WAAW;YACnB,MAAM;YACN,OAAO,EAAE,CAAC,qBAAY,EAAE,GAAG,OAAO,CAAC;YACnC,SAAS;YACT,OAAO,EAAE,SAAS;SACrB,CAAC;IACN,CAAC;CACJ;AAhQD,kCAgQC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { applyDecorators } from '@nestjs/common';
|
|
2
|
+
type LogtoProtectedOptions<T> = Partial<{
|
|
3
|
+
requiredScopes: string[];
|
|
4
|
+
requiredRoles: (T | 'management-point3')[];
|
|
5
|
+
}>;
|
|
6
|
+
export declare function LogtoProtected<RoleType>(options?: LogtoProtectedOptions<RoleType>): ReturnType<typeof applyDecorators>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogtoProtected = LogtoProtected;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const guard_1 = require("./guard");
|
|
6
|
+
function LogtoProtected(options) {
|
|
7
|
+
const { requiredScopes, requiredRoles } = options ?? {};
|
|
8
|
+
return (0, common_1.applyDecorators)((0, common_1.UseGuards)(guard_1.LogtoTokenGuard), (0, common_1.SetMetadata)('requiredScopes', requiredScopes && requiredScopes.length > 0 ? requiredScopes : undefined), (0, common_1.SetMetadata)('requiredRoles', requiredRoles && requiredRoles.length > 0 ? requiredRoles : undefined));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../stateless/decorator.ts"],"names":[],"mappings":";;AAQA,wCAOC;AAfD,2CAAyE;AACzE,mCAA0C;AAO1C,SAAgB,cAAc,CAAW,OAAyC;IAChF,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACxD,OAAO,IAAA,wBAAe,EACpB,IAAA,kBAAS,EAAC,uBAAe,CAAC,EAC1B,IAAA,oBAAW,EAAC,gBAAgB,EAAE,cAAc,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,EACvG,IAAA,oBAAW,EAAC,eAAe,EAAE,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CACpG,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { LogtoTokenVerifier } from '../token';
|
|
3
|
+
export declare const LogtoTokenGuardToken: unique symbol;
|
|
4
|
+
export declare class LogtoTokenGuard implements CanActivate {
|
|
5
|
+
private tokenVerifier;
|
|
6
|
+
private reflector;
|
|
7
|
+
constructor(tokenVerifier: LogtoTokenVerifier);
|
|
8
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
9
|
+
private extractBearerTokenFrom;
|
|
10
|
+
}
|