@point3/logto-module 1.0.22 → 1.1.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.
- package/.idea/copilot.data.migration.ask2agent.xml +6 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/misc.xml +7 -0
- package/.idea/modules.xml +8 -0
- package/.idea/point3-logto-module.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/.serena/project.yml +87 -0
- package/README.md +124 -80
- package/client/config.ts +62 -0
- package/client/logto-login-session.ts +8 -17
- package/client/m2m-client.ts +15 -59
- package/client/oauth-client.ts +18 -32
- package/client/types.ts +1 -1
- package/dist/client/config.d.ts +23 -0
- package/dist/client/logto-login-session.d.ts +2 -3
- package/dist/client/logto-login-session.js +4 -13
- package/dist/client/logto-login-session.js.map +1 -1
- package/dist/client/m2m-client.d.ts +3 -4
- package/dist/client/m2m-client.js +12 -41
- package/dist/client/m2m-client.js.map +1 -1
- package/dist/client/oauth-client.d.ts +4 -4
- package/dist/client/oauth-client.js +16 -22
- package/dist/client/oauth-client.js.map +1 -1
- package/dist/client/types.d.ts +1 -1
- package/dist/module.d.ts +24 -1
- package/dist/module.js +124 -23
- package/dist/module.js.map +1 -1
- package/dist/token/verifier.d.ts +3 -3
- package/dist/token/verifier.js +5 -14
- package/dist/token/verifier.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/module.ts +264 -80
- package/package.json +1 -1
- package/token/verifier.ts +8 -17
package/client/m2m-client.ts
CHANGED
|
@@ -2,26 +2,24 @@
|
|
|
2
2
|
* Logto M2M(Machine-to-Machine) 클라이언트
|
|
3
3
|
* - Logto API의 M2M 인증 및 사용자/역할 관리 기능 제공
|
|
4
4
|
* - NestJS DI 시스템에 등록됨
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* @author
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
Inject,
|
|
11
10
|
Injectable,
|
|
12
11
|
Global,
|
|
13
12
|
LoggerService,
|
|
14
13
|
} from "@nestjs/common";
|
|
15
|
-
import { ConfigService } from "@nestjs/config";
|
|
16
14
|
|
|
17
15
|
import {
|
|
18
16
|
LogtoConfig,
|
|
17
|
+
LogtoM2MConfig,
|
|
19
18
|
GrantType,
|
|
20
19
|
} from "./config";
|
|
21
20
|
import {
|
|
22
21
|
AccessToken,
|
|
23
22
|
LogtoTokenVerifier,
|
|
24
|
-
LogtoTokenVerifierToken,
|
|
25
23
|
} from "../token";
|
|
26
24
|
import {
|
|
27
25
|
LogtoOAuthRESTTemplate,
|
|
@@ -31,13 +29,10 @@ import {
|
|
|
31
29
|
LogtoUser,
|
|
32
30
|
LogtoUserResponse,
|
|
33
31
|
VerificationMethodType,
|
|
34
|
-
LogtoLoggerServiceToken
|
|
35
32
|
} from "./types";
|
|
36
33
|
import { p3Values, axiosAdapter } from "point3-common-tool";
|
|
37
34
|
import {
|
|
38
35
|
UserMissingRequiredFieldsError,
|
|
39
|
-
UserNotFoundError,
|
|
40
|
-
MultipleUsersFoundError,
|
|
41
36
|
} from "../errors";
|
|
42
37
|
|
|
43
38
|
// DI 토큰
|
|
@@ -75,22 +70,17 @@ export class LogtoM2MClient {
|
|
|
75
70
|
private readonly apiRestTemplate: axiosAdapter.RESTTemplate;
|
|
76
71
|
|
|
77
72
|
constructor(
|
|
78
|
-
|
|
79
|
-
private readonly configService: ConfigService,
|
|
80
|
-
|
|
81
|
-
@Inject(LogtoTokenVerifierToken)
|
|
73
|
+
private readonly config: LogtoM2MConfig,
|
|
82
74
|
private readonly tokenVerifier: LogtoTokenVerifier,
|
|
83
|
-
|
|
84
|
-
@Inject(LogtoLoggerServiceToken)
|
|
85
75
|
private readonly logger: LoggerService,
|
|
86
76
|
) {
|
|
87
|
-
//
|
|
77
|
+
// config 기반 Logto 설정
|
|
88
78
|
this.logtoConfig = {
|
|
89
|
-
endpoint:
|
|
90
|
-
appId:
|
|
91
|
-
appSecret:
|
|
92
|
-
scopes:
|
|
93
|
-
resources: [
|
|
79
|
+
endpoint: config.endpoint,
|
|
80
|
+
appId: config.clientId,
|
|
81
|
+
appSecret: config.clientSecret,
|
|
82
|
+
scopes: config.scopes,
|
|
83
|
+
resources: [config.resource],
|
|
94
84
|
grantType: GrantType.ClientCredentials,
|
|
95
85
|
};
|
|
96
86
|
|
|
@@ -104,7 +94,7 @@ export class LogtoM2MClient {
|
|
|
104
94
|
// API용 REST 템플릿 초기화
|
|
105
95
|
this.apiRestTemplate = new LogtoOAuthRESTTemplate(
|
|
106
96
|
this.logger,
|
|
107
|
-
|
|
97
|
+
config.apiUrl,
|
|
108
98
|
);
|
|
109
99
|
}
|
|
110
100
|
|
|
@@ -142,7 +132,7 @@ export class LogtoM2MClient {
|
|
|
142
132
|
/**
|
|
143
133
|
* PAT 토큰을 이용해 AccessToken 발급
|
|
144
134
|
*/
|
|
145
|
-
public async fetchAccessTokenByPAT(pat: string): Promise<{ accessToken: string }> {
|
|
135
|
+
public async fetchAccessTokenByPAT(pat: string): Promise<{ accessToken: string }> {
|
|
146
136
|
try {
|
|
147
137
|
const parameters = new URLSearchParams();
|
|
148
138
|
parameters.set("grant_type", "urn:ietf:params:oauth:grant-type:token-exchange");
|
|
@@ -151,15 +141,15 @@ export class LogtoM2MClient {
|
|
|
151
141
|
parameters.set("subject_token", pat);
|
|
152
142
|
parameters.set("subject_token_type", "urn:logto:token-type:personal_access_token");
|
|
153
143
|
|
|
154
|
-
// check the request
|
|
144
|
+
// check the request
|
|
155
145
|
const response = await this.authRestTemplate.post(
|
|
156
146
|
`${this.logtoConfig.endpoint}/token`,
|
|
157
147
|
parameters.toString(),
|
|
158
148
|
{
|
|
159
149
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
160
150
|
}
|
|
161
|
-
);
|
|
162
|
-
|
|
151
|
+
);
|
|
152
|
+
|
|
163
153
|
|
|
164
154
|
console.log(response);
|
|
165
155
|
return {
|
|
@@ -266,7 +256,7 @@ export class LogtoM2MClient {
|
|
|
266
256
|
async createUser(user: LogtoUser): Promise<string> {
|
|
267
257
|
await this.getAccessToken();
|
|
268
258
|
|
|
269
|
-
if (user.username && user.primaryEmail && user.password && user.
|
|
259
|
+
if (user.username && user.primaryEmail && user.password && user.name) {
|
|
270
260
|
user.passwordAlgorithm = user.passwordAlgorithm ?? LogtoPasswordAlgorithm.Argon2i;
|
|
271
261
|
const response = await this.apiRestTemplate.post<{ id: string }>('/users', user);
|
|
272
262
|
return response.data.id;
|
|
@@ -301,40 +291,6 @@ export class LogtoM2MClient {
|
|
|
301
291
|
return response.data;
|
|
302
292
|
}
|
|
303
293
|
|
|
304
|
-
/**
|
|
305
|
-
* 이메일+휴대폰으로 사용자 단일 조회 (여러명/없음 예외 처리)
|
|
306
|
-
* @param email 이메일
|
|
307
|
-
* @param phone 휴대폰번호
|
|
308
|
-
*/
|
|
309
|
-
async getUsersByEmailAndPhone(
|
|
310
|
-
email: string,
|
|
311
|
-
phone: string,
|
|
312
|
-
): Promise<LogtoUserResponse> {
|
|
313
|
-
await this.getAccessToken();
|
|
314
|
-
|
|
315
|
-
const params = new URLSearchParams();
|
|
316
|
-
params.set('search.primaryEmail', email);
|
|
317
|
-
params.set('search.primaryPhone', generatePhoneNumberWithCountryCode('82', phone));
|
|
318
|
-
params.set('joint', 'and');
|
|
319
|
-
params.set('mode.primaryEmail', 'exact');
|
|
320
|
-
params.set('mode.primaryPhone', 'exact');
|
|
321
|
-
|
|
322
|
-
const response = await this.apiRestTemplate.get<LogtoUserResponse[]>(
|
|
323
|
-
`/users?${params.toString()}`,
|
|
324
|
-
);
|
|
325
|
-
const logtoUsers = response.data;
|
|
326
|
-
|
|
327
|
-
if (logtoUsers.length === 1) {
|
|
328
|
-
return logtoUsers[0];
|
|
329
|
-
}
|
|
330
|
-
if (logtoUsers.length === 0) {
|
|
331
|
-
this.logger.error(`사용자 없음: email=${email}, phone=${phone}`, this.constructor.name);
|
|
332
|
-
throw new UserNotFoundError(email, phone);
|
|
333
|
-
}
|
|
334
|
-
this.logger.error(`여러 사용자 발견: email=${email}, phone=${phone}`, this.constructor.name);
|
|
335
|
-
this.logger.error(JSON.stringify(logtoUsers), this.constructor.name);
|
|
336
|
-
throw new MultipleUsersFoundError(email, phone);
|
|
337
|
-
}
|
|
338
294
|
|
|
339
295
|
/**
|
|
340
296
|
* username으로 사용자 단일 조회
|
package/client/oauth-client.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Injectable, Global, LoggerService } from "@nestjs/common";
|
|
2
2
|
import axios, { AxiosResponse } from "axios";
|
|
3
|
-
import { GrantType,
|
|
4
|
-
import { ConfigService } from "@nestjs/config";
|
|
3
|
+
import { GrantType, LogtoConfig, LogtoOAuthConfig } from "./config";
|
|
5
4
|
import { axiosAdapter, p3Values } from "point3-common-tool";
|
|
6
5
|
import {
|
|
7
6
|
TokenRevocationFailedError,
|
|
@@ -48,25 +47,22 @@ export class OAuthClient {
|
|
|
48
47
|
|
|
49
48
|
/**
|
|
50
49
|
* 생성자
|
|
51
|
-
* @param
|
|
50
|
+
* @param config OAuth 설정
|
|
52
51
|
* @param logger 로거 서비스
|
|
53
52
|
*/
|
|
54
53
|
constructor(
|
|
55
|
-
|
|
56
|
-
private
|
|
57
|
-
|
|
58
|
-
@Inject(LogtoLoggerServiceToken)
|
|
59
|
-
private logger: LoggerService
|
|
54
|
+
private readonly config: LogtoOAuthConfig,
|
|
55
|
+
private readonly logger: LoggerService
|
|
60
56
|
) {
|
|
61
57
|
// Logto 설정 초기화
|
|
62
58
|
this.logtoConfig = {
|
|
63
|
-
endpoint:
|
|
64
|
-
appId:
|
|
65
|
-
appSecret:
|
|
66
|
-
resources:
|
|
67
|
-
scopes:
|
|
68
|
-
prompt:
|
|
69
|
-
redirectUri:
|
|
59
|
+
endpoint: config.endpoint,
|
|
60
|
+
appId: config.clientId,
|
|
61
|
+
appSecret: config.clientSecret,
|
|
62
|
+
resources: config.resources,
|
|
63
|
+
scopes: config.scopes,
|
|
64
|
+
prompt: config.prompt,
|
|
65
|
+
redirectUri: config.redirectUri,
|
|
70
66
|
grantType: GrantType.AuthorizationCode,
|
|
71
67
|
};
|
|
72
68
|
|
|
@@ -94,25 +90,17 @@ export class OAuthClient {
|
|
|
94
90
|
|
|
95
91
|
// 대시보드 로그인일 경우 별도 URI, 실패시 기본 URI로 폴백
|
|
96
92
|
if (signInType === SignInType.Dashboard) {
|
|
97
|
-
|
|
98
|
-
uri = new URL(
|
|
99
|
-
|
|
100
|
-
"LOGTO_DASHBOARD_SIGN_IN_URI"
|
|
101
|
-
)}/auth`
|
|
102
|
-
);
|
|
103
|
-
} catch (error) {
|
|
93
|
+
if (this.config.dashboardSignInUri) {
|
|
94
|
+
uri = new URL(`${this.config.dashboardSignInUri}/auth`);
|
|
95
|
+
} else {
|
|
104
96
|
this.logger.warn(
|
|
105
97
|
"대시보드 로그인 URI 설정을 찾을 수 없어 기본 URI를 사용합니다.",
|
|
106
98
|
this.constructor.name
|
|
107
99
|
);
|
|
108
|
-
uri = new URL(
|
|
109
|
-
`${this.configService.get<string>("LOGTO_SIGN_IN_URI")}/auth`
|
|
110
|
-
);
|
|
100
|
+
uri = new URL(`${this.config.signInUri}/auth`);
|
|
111
101
|
}
|
|
112
102
|
} else {
|
|
113
|
-
uri = new URL(
|
|
114
|
-
`${this.configService.get<string>("LOGTO_SIGN_IN_URI")}/auth`
|
|
115
|
-
);
|
|
103
|
+
uri = new URL(`${this.config.signInUri}/auth`);
|
|
116
104
|
}
|
|
117
105
|
|
|
118
106
|
// 상태값 생성 (CSRF 방지)
|
|
@@ -139,9 +127,7 @@ export class OAuthClient {
|
|
|
139
127
|
*/
|
|
140
128
|
public async getSignOutURI(): Promise<string> {
|
|
141
129
|
try {
|
|
142
|
-
const uri = new URL(
|
|
143
|
-
`${this.configService.get<string>("LOGTO_SIGN_IN_URI")}/session/end`
|
|
144
|
-
);
|
|
130
|
+
const uri = new URL(`${this.config.signInUri}/session/end`);
|
|
145
131
|
|
|
146
132
|
// 로그아웃 후 리다이렉트 URI 및 클라이언트 ID 설정
|
|
147
133
|
uri.searchParams.set("redirect_uri", this.logtoConfig.redirectUri!);
|
package/client/types.ts
CHANGED
|
@@ -44,7 +44,7 @@ export enum LogtoPasswordAlgorithm {
|
|
|
44
44
|
*/
|
|
45
45
|
export type LogtoUser = {
|
|
46
46
|
username: string; // Guid's string value(dash to underscore)
|
|
47
|
-
primaryPhone
|
|
47
|
+
primaryPhone?: string;
|
|
48
48
|
primaryEmail: string;
|
|
49
49
|
password: string;
|
|
50
50
|
passwordAlgorithm?: LogtoPasswordAlgorithm; // default: Argon2i
|
package/dist/client/config.d.ts
CHANGED
|
@@ -19,3 +19,26 @@ export declare enum GrantType {
|
|
|
19
19
|
ClientCredentials = "client_credentials",
|
|
20
20
|
RefreshToken = "refresh_token"
|
|
21
21
|
}
|
|
22
|
+
export interface LogtoVerifierConfig {
|
|
23
|
+
jwksUri: string;
|
|
24
|
+
issuer: string;
|
|
25
|
+
}
|
|
26
|
+
export interface LogtoOAuthConfig {
|
|
27
|
+
endpoint: string;
|
|
28
|
+
clientId: string;
|
|
29
|
+
clientSecret: string;
|
|
30
|
+
resources: string[];
|
|
31
|
+
scopes: string[];
|
|
32
|
+
prompt: Prompt;
|
|
33
|
+
redirectUri: string;
|
|
34
|
+
signInUri: string;
|
|
35
|
+
dashboardSignInUri?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface LogtoM2MConfig {
|
|
38
|
+
endpoint: string;
|
|
39
|
+
clientId: string;
|
|
40
|
+
clientSecret: string;
|
|
41
|
+
resource: string;
|
|
42
|
+
apiUrl: string;
|
|
43
|
+
scopes: string[];
|
|
44
|
+
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { LoggerService } from "@nestjs/common";
|
|
2
|
-
import { ConfigService } from "@nestjs/config";
|
|
3
2
|
import { AxiosResponse } from "axios";
|
|
4
3
|
import { OAuthClient, SignInType } from "./oauth-client";
|
|
5
4
|
export declare const LogtoLoginSessionToken: unique symbol;
|
|
6
5
|
export declare class LogtoLoginSession {
|
|
6
|
+
private readonly apiUrl;
|
|
7
7
|
private readonly logger;
|
|
8
|
-
private readonly configService;
|
|
9
8
|
private readonly oauthClient;
|
|
10
9
|
private readonly apiRestTemplate;
|
|
11
|
-
constructor(
|
|
10
|
+
constructor(apiUrl: string, logger: LoggerService, oauthClient: OAuthClient);
|
|
12
11
|
createSignInSession(signInType: SignInType): Promise<{
|
|
13
12
|
response: AxiosResponse | undefined;
|
|
14
13
|
state: string;
|
|
@@ -8,27 +8,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
13
|
};
|
|
17
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
15
|
exports.LogtoLoginSession = exports.LogtoLoginSessionToken = void 0;
|
|
19
16
|
const common_1 = require("@nestjs/common");
|
|
20
|
-
const config_1 = require("@nestjs/config");
|
|
21
17
|
const axios_1 = __importDefault(require("axios"));
|
|
22
18
|
const oauth_client_1 = require("./oauth-client");
|
|
23
19
|
const types_1 = require("./types");
|
|
24
20
|
exports.LogtoLoginSessionToken = Symbol.for("LogtoLoginSession");
|
|
25
21
|
let LogtoLoginSession = class LogtoLoginSession {
|
|
26
|
-
constructor(
|
|
22
|
+
constructor(apiUrl, logger, oauthClient) {
|
|
23
|
+
this.apiUrl = apiUrl;
|
|
27
24
|
this.logger = logger;
|
|
28
|
-
this.configService = configService;
|
|
29
25
|
this.oauthClient = oauthClient;
|
|
30
|
-
|
|
31
|
-
this.apiRestTemplate = new types_1.LogtoOAuthRESTTemplate(this.logger, baseURL);
|
|
26
|
+
this.apiRestTemplate = new types_1.LogtoOAuthRESTTemplate(this.logger, apiUrl);
|
|
32
27
|
}
|
|
33
28
|
async createSignInSession(signInType) {
|
|
34
29
|
const { uri, state } = this.oauthClient.getSignInURI(signInType);
|
|
@@ -119,10 +114,6 @@ let LogtoLoginSession = class LogtoLoginSession {
|
|
|
119
114
|
exports.LogtoLoginSession = LogtoLoginSession;
|
|
120
115
|
exports.LogtoLoginSession = LogtoLoginSession = __decorate([
|
|
121
116
|
(0, common_1.Injectable)(),
|
|
122
|
-
|
|
123
|
-
__param(1, (0, common_1.Inject)(config_1.ConfigService)),
|
|
124
|
-
__param(2, (0, common_1.Inject)(oauth_client_1.OAuthClientToken)),
|
|
125
|
-
__metadata("design:paramtypes", [Object, config_1.ConfigService,
|
|
126
|
-
oauth_client_1.OAuthClient])
|
|
117
|
+
__metadata("design:paramtypes", [String, Object, oauth_client_1.OAuthClient])
|
|
127
118
|
], LogtoLoginSession);
|
|
128
119
|
//# sourceMappingURL=logto-login-session.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logto-login-session.js","sourceRoot":"","sources":["../../client/logto-login-session.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logto-login-session.js","sourceRoot":"","sources":["../../client/logto-login-session.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2D;AAC3D,kDAA6C;AAG7C,iDAGwB;AAExB,mCAEiB;AAGJ,QAAA,sBAAsB,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AAoB/D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAa1B,YACqB,MAAc,EACd,MAAqB,EACrB,WAAwB;QAFxB,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAe;QACrB,gBAAW,GAAX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IAAI,GAAG,IAAI,MAAM,IAAI,GAAG;YAC1D,eAAe,EAAE,IAAI;YACrB,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;SAC9B,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IACpB,CAAC;IASM,KAAK,CAAC,OAAO,CAAC,MAAc;QAC/B,IAAI,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC5C,sBAAsB,EACtB,EAAE,EACF;gBACI,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;gBAC3B,eAAe,EAAE,IAAI;aACxB,CACJ,CAAC;YACF,OAAO,QAAQ,CAAC,IAAI,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ,CAAA;AAnMY,8CAAiB;4BAAjB,iBAAiB;IAlB7B,IAAA,mBAAU,GAAE;qDAkCyB,0BAAW;GAhBpC,iBAAiB,CAmM7B"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { LoggerService } from "@nestjs/common";
|
|
2
|
-
import {
|
|
2
|
+
import { LogtoM2MConfig } from "./config";
|
|
3
3
|
import { LogtoTokenVerifier } from "../token";
|
|
4
4
|
import { LogtoRole, LogtoRoleResponse, LogtoUser, LogtoUserResponse } from "./types";
|
|
5
5
|
import { p3Values } from "point3-common-tool";
|
|
6
6
|
export declare const LogtoM2MClientToken: unique symbol;
|
|
7
7
|
export declare class LogtoM2MClient {
|
|
8
|
-
private readonly
|
|
8
|
+
private readonly config;
|
|
9
9
|
private readonly tokenVerifier;
|
|
10
10
|
private readonly logger;
|
|
11
11
|
private logtoConfig;
|
|
12
12
|
private accessToken?;
|
|
13
13
|
private readonly authRestTemplate;
|
|
14
14
|
private readonly apiRestTemplate;
|
|
15
|
-
constructor(
|
|
15
|
+
constructor(config: LogtoM2MConfig, tokenVerifier: LogtoTokenVerifier, logger: LoggerService);
|
|
16
16
|
fetchAccessToken(): Promise<void>;
|
|
17
17
|
fetchAccessTokenByPAT(pat: string): Promise<{
|
|
18
18
|
accessToken: string;
|
|
@@ -25,7 +25,6 @@ export declare class LogtoM2MClient {
|
|
|
25
25
|
createUser(user: LogtoUser): Promise<string>;
|
|
26
26
|
updateUserClientInfo(userId: string, clientId?: string): Promise<void>;
|
|
27
27
|
getUser(id: string): Promise<LogtoUserResponse>;
|
|
28
|
-
getUsersByEmailAndPhone(email: string, phone: string): Promise<LogtoUserResponse>;
|
|
29
28
|
getUserByUsername(username: string): Promise<LogtoUserResponse>;
|
|
30
29
|
suspendUser(userId: string): Promise<LogtoUserResponse>;
|
|
31
30
|
deleteUser(userId: string): Promise<void>;
|
|
@@ -8,36 +8,32 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.LogtoM2MClient = exports.LogtoM2MClientToken = void 0;
|
|
16
13
|
exports.generatePhoneNumberWithCountryCode = generatePhoneNumberWithCountryCode;
|
|
17
14
|
const common_1 = require("@nestjs/common");
|
|
18
|
-
const config_1 = require("
|
|
19
|
-
const config_2 = require("./config");
|
|
15
|
+
const config_1 = require("./config");
|
|
20
16
|
const token_1 = require("../token");
|
|
21
17
|
const types_1 = require("./types");
|
|
22
18
|
const point3_common_tool_1 = require("point3-common-tool");
|
|
23
19
|
const errors_1 = require("../errors");
|
|
24
20
|
exports.LogtoM2MClientToken = Symbol.for("LogtoM2MClient");
|
|
25
21
|
let LogtoM2MClient = class LogtoM2MClient {
|
|
26
|
-
constructor(
|
|
27
|
-
this.
|
|
22
|
+
constructor(config, tokenVerifier, logger) {
|
|
23
|
+
this.config = config;
|
|
28
24
|
this.tokenVerifier = tokenVerifier;
|
|
29
25
|
this.logger = logger;
|
|
30
26
|
this.logtoConfig = {
|
|
31
|
-
endpoint:
|
|
32
|
-
appId:
|
|
33
|
-
appSecret:
|
|
34
|
-
scopes:
|
|
35
|
-
resources: [
|
|
36
|
-
grantType:
|
|
27
|
+
endpoint: config.endpoint,
|
|
28
|
+
appId: config.clientId,
|
|
29
|
+
appSecret: config.clientSecret,
|
|
30
|
+
scopes: config.scopes,
|
|
31
|
+
resources: [config.resource],
|
|
32
|
+
grantType: config_1.GrantType.ClientCredentials,
|
|
37
33
|
};
|
|
38
34
|
this.authRestTemplate = new types_1.LogtoOAuthRESTTemplate(this.logger, this.logtoConfig.endpoint);
|
|
39
35
|
this.authRestTemplate.setBasic(this.logtoConfig.appId, this.logtoConfig.appSecret);
|
|
40
|
-
this.apiRestTemplate = new types_1.LogtoOAuthRESTTemplate(this.logger,
|
|
36
|
+
this.apiRestTemplate = new types_1.LogtoOAuthRESTTemplate(this.logger, config.apiUrl);
|
|
41
37
|
}
|
|
42
38
|
async fetchAccessToken() {
|
|
43
39
|
const params = new URLSearchParams();
|
|
@@ -115,7 +111,7 @@ let LogtoM2MClient = class LogtoM2MClient {
|
|
|
115
111
|
}
|
|
116
112
|
async createUser(user) {
|
|
117
113
|
await this.getAccessToken();
|
|
118
|
-
if (user.username && user.primaryEmail && user.password && user.
|
|
114
|
+
if (user.username && user.primaryEmail && user.password && user.name) {
|
|
119
115
|
user.passwordAlgorithm = user.passwordAlgorithm ?? types_1.LogtoPasswordAlgorithm.Argon2i;
|
|
120
116
|
const response = await this.apiRestTemplate.post('/users', user);
|
|
121
117
|
return response.data.id;
|
|
@@ -134,27 +130,6 @@ let LogtoM2MClient = class LogtoM2MClient {
|
|
|
134
130
|
const response = await this.apiRestTemplate.get(`/users/${id}`);
|
|
135
131
|
return response.data;
|
|
136
132
|
}
|
|
137
|
-
async getUsersByEmailAndPhone(email, phone) {
|
|
138
|
-
await this.getAccessToken();
|
|
139
|
-
const params = new URLSearchParams();
|
|
140
|
-
params.set('search.primaryEmail', email);
|
|
141
|
-
params.set('search.primaryPhone', generatePhoneNumberWithCountryCode('82', phone));
|
|
142
|
-
params.set('joint', 'and');
|
|
143
|
-
params.set('mode.primaryEmail', 'exact');
|
|
144
|
-
params.set('mode.primaryPhone', 'exact');
|
|
145
|
-
const response = await this.apiRestTemplate.get(`/users?${params.toString()}`);
|
|
146
|
-
const logtoUsers = response.data;
|
|
147
|
-
if (logtoUsers.length === 1) {
|
|
148
|
-
return logtoUsers[0];
|
|
149
|
-
}
|
|
150
|
-
if (logtoUsers.length === 0) {
|
|
151
|
-
this.logger.error(`사용자 없음: email=${email}, phone=${phone}`, this.constructor.name);
|
|
152
|
-
throw new errors_1.UserNotFoundError(email, phone);
|
|
153
|
-
}
|
|
154
|
-
this.logger.error(`여러 사용자 발견: email=${email}, phone=${phone}`, this.constructor.name);
|
|
155
|
-
this.logger.error(JSON.stringify(logtoUsers), this.constructor.name);
|
|
156
|
-
throw new errors_1.MultipleUsersFoundError(email, phone);
|
|
157
|
-
}
|
|
158
133
|
async getUserByUsername(username) {
|
|
159
134
|
await this.getAccessToken();
|
|
160
135
|
const params = new URLSearchParams();
|
|
@@ -210,11 +185,7 @@ exports.LogtoM2MClient = LogtoM2MClient;
|
|
|
210
185
|
exports.LogtoM2MClient = LogtoM2MClient = __decorate([
|
|
211
186
|
(0, common_1.Global)(),
|
|
212
187
|
(0, common_1.Injectable)(),
|
|
213
|
-
|
|
214
|
-
__param(1, (0, common_1.Inject)(token_1.LogtoTokenVerifierToken)),
|
|
215
|
-
__param(2, (0, common_1.Inject)(types_1.LogtoLoggerServiceToken)),
|
|
216
|
-
__metadata("design:paramtypes", [config_1.ConfigService,
|
|
217
|
-
token_1.LogtoTokenVerifier, Object])
|
|
188
|
+
__metadata("design:paramtypes", [Object, token_1.LogtoTokenVerifier, Object])
|
|
218
189
|
], LogtoM2MClient);
|
|
219
190
|
function generatePhoneNumberWithCountryCode(countryCode, phoneNumber) {
|
|
220
191
|
if (phoneNumber.startsWith('0')) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"m2m-client.js","sourceRoot":"","sources":["../../client/m2m-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"m2m-client.js","sourceRoot":"","sources":["../../client/m2m-client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAmaA,gFAKC;AAhaD,2CAIwB;AAExB,qCAIkB;AAClB,oCAGkB;AAClB,mCAQiB;AACjB,2DAA4D;AAC5D,sCAEmB;AAGN,QAAA,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;AAwBzD,IAAM,cAAc,GAApB,MAAM,cAAc;IASvB,YACqB,MAAsB,EACtB,aAAiC,EACjC,MAAqB;QAFrB,WAAM,GAAN,MAAM,CAAgB;QACtB,kBAAa,GAAb,aAAa,CAAoB;QACjC,WAAM,GAAN,MAAM,CAAe;QAGtC,IAAI,CAAC,WAAW,GAAG;YACf,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,KAAK,EAAE,MAAM,CAAC,QAAQ;YACtB,SAAS,EAAE,MAAM,CAAC,YAAY;YAC9B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,SAAS,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC;YAC5B,SAAS,EAAE,kBAAS,CAAC,iBAAiB;SACzC,CAAC;QAGF,IAAI,CAAC,gBAAgB,GAAG,IAAI,8BAAsB,CAC9C,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,WAAW,CAAC,QAAQ,CAC5B,CAAC;QACF,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAGnF,IAAI,CAAC,eAAe,GAAG,IA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AgB,kCAAkC,CAAC,WAAmB,EAAE,WAAmB;IACvF,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9B,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,GAAG,WAAW,GAAG,WAAW,EAAE,CAAC;AAC1C,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { LoggerService } from "@nestjs/common";
|
|
2
|
-
import {
|
|
2
|
+
import { LogtoOAuthConfig } from "./config";
|
|
3
3
|
export declare const OAuthClientToken = "OAuthClient";
|
|
4
4
|
export declare class OAuthClient {
|
|
5
|
-
private
|
|
6
|
-
private logger;
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly logger;
|
|
7
7
|
private logtoConfig;
|
|
8
8
|
private logtoRestTemplate;
|
|
9
9
|
static readonly prefix: string;
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(config: LogtoOAuthConfig, logger: LoggerService);
|
|
11
11
|
getSignInURI(signInType: SignInType): {
|
|
12
12
|
uri: string;
|
|
13
13
|
state: string;
|
|
@@ -8,9 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
13
|
};
|
|
@@ -20,24 +17,23 @@ exports.SignInType = exports.OAuthClient = exports.OAuthClientToken = void 0;
|
|
|
20
17
|
const common_1 = require("@nestjs/common");
|
|
21
18
|
const axios_1 = __importDefault(require("axios"));
|
|
22
19
|
const config_1 = require("./config");
|
|
23
|
-
const config_2 = require("@nestjs/config");
|
|
24
20
|
const point3_common_tool_1 = require("point3-common-tool");
|
|
25
21
|
const errors_1 = require("../errors");
|
|
26
22
|
const types_1 = require("./types");
|
|
27
23
|
const Gulid = point3_common_tool_1.p3Values.Gulid;
|
|
28
24
|
exports.OAuthClientToken = "OAuthClient";
|
|
29
25
|
let OAuthClient = OAuthClient_1 = class OAuthClient {
|
|
30
|
-
constructor(
|
|
31
|
-
this.
|
|
26
|
+
constructor(config, logger) {
|
|
27
|
+
this.config = config;
|
|
32
28
|
this.logger = logger;
|
|
33
29
|
this.logtoConfig = {
|
|
34
|
-
endpoint:
|
|
35
|
-
appId:
|
|
36
|
-
appSecret:
|
|
37
|
-
resources:
|
|
38
|
-
scopes:
|
|
39
|
-
prompt:
|
|
40
|
-
redirectUri:
|
|
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,
|
|
41
37
|
grantType: config_1.GrantType.AuthorizationCode,
|
|
42
38
|
};
|
|
43
39
|
this.logtoRestTemplate = new types_1.LogtoOAuthRESTTemplate(logger, this.logtoConfig.endpoint);
|
|
@@ -47,16 +43,16 @@ let OAuthClient = OAuthClient_1 = class OAuthClient {
|
|
|
47
43
|
try {
|
|
48
44
|
let uri;
|
|
49
45
|
if (signInType === SignInType.Dashboard) {
|
|
50
|
-
|
|
51
|
-
uri = new URL(`${this.
|
|
46
|
+
if (this.config.dashboardSignInUri) {
|
|
47
|
+
uri = new URL(`${this.config.dashboardSignInUri}/auth`);
|
|
52
48
|
}
|
|
53
|
-
|
|
49
|
+
else {
|
|
54
50
|
this.logger.warn("대시보드 로그인 URI 설정을 찾을 수 없어 기본 URI를 사용합니다.", this.constructor.name);
|
|
55
|
-
uri = new URL(`${this.
|
|
51
|
+
uri = new URL(`${this.config.signInUri}/auth`);
|
|
56
52
|
}
|
|
57
53
|
}
|
|
58
54
|
else {
|
|
59
|
-
uri = new URL(`${this.
|
|
55
|
+
uri = new URL(`${this.config.signInUri}/auth`);
|
|
60
56
|
}
|
|
61
57
|
const state = Gulid.create(OAuthClient_1.prefix);
|
|
62
58
|
uri.searchParams.set("redirect_uri", this.logtoConfig.redirectUri);
|
|
@@ -74,7 +70,7 @@ let OAuthClient = OAuthClient_1 = class OAuthClient {
|
|
|
74
70
|
}
|
|
75
71
|
async getSignOutURI() {
|
|
76
72
|
try {
|
|
77
|
-
const uri = new URL(`${this.
|
|
73
|
+
const uri = new URL(`${this.config.signInUri}/session/end`);
|
|
78
74
|
uri.searchParams.set("redirect_uri", this.logtoConfig.redirectUri);
|
|
79
75
|
uri.searchParams.set("client_id", this.logtoConfig.appId);
|
|
80
76
|
return uri.toString();
|
|
@@ -123,9 +119,7 @@ OAuthClient.prefix = "signin";
|
|
|
123
119
|
exports.OAuthClient = OAuthClient = OAuthClient_1 = __decorate([
|
|
124
120
|
(0, common_1.Global)(),
|
|
125
121
|
(0, common_1.Injectable)(),
|
|
126
|
-
|
|
127
|
-
__param(1, (0, common_1.Inject)(types_1.LogtoLoggerServiceToken)),
|
|
128
|
-
__metadata("design:paramtypes", [config_2.ConfigService, Object])
|
|
122
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
129
123
|
], OAuthClient);
|
|
130
124
|
var SignInType;
|
|
131
125
|
(function (SignInType) {
|