@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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const config_1 = require("@nestjs/config");
|
|
5
|
+
const point3_common_tool_1 = require("point3-common-tool");
|
|
6
|
+
const __1 = require("..");
|
|
7
|
+
const token_1 = require("../../token");
|
|
8
|
+
const common_1 = require("@nestjs/common");
|
|
9
|
+
describe('M2mclient를 이용한 Logto API 테스트', () => {
|
|
10
|
+
let m2mClient;
|
|
11
|
+
let testUser;
|
|
12
|
+
let testUserId = 'bead71jr45u1';
|
|
13
|
+
let testRoleId = '0fwcgs8okjy7lav216sb3';
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
const module = await testing_1.Test.createTestingModule({
|
|
16
|
+
imports: [
|
|
17
|
+
config_1.ConfigModule.forRoot({
|
|
18
|
+
envFilePath: `env/.env.${process.env.NODE_ENV}`,
|
|
19
|
+
isGlobal: true,
|
|
20
|
+
})
|
|
21
|
+
],
|
|
22
|
+
providers: [
|
|
23
|
+
{
|
|
24
|
+
provide: token_1.LogtoTokenVerifierToken,
|
|
25
|
+
useClass: token_1.LogtoTokenVerifier
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
provide: __1.LogtoLoggerServiceToken,
|
|
29
|
+
useClass: common_1.ConsoleLogger
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
}).compile();
|
|
33
|
+
m2mClient = module.get(__1.LogtoM2MClientToken);
|
|
34
|
+
const randomNumber = Math.floor(1000 + Math.random() * 9000);
|
|
35
|
+
testUser = {
|
|
36
|
+
username: point3_common_tool_1.p3Values.Guid.create('test').toString().replace(/-/g, '_'),
|
|
37
|
+
name: 'test' + randomNumber,
|
|
38
|
+
primaryEmail: 'test' + randomNumber + '@test.com',
|
|
39
|
+
password: 'test123',
|
|
40
|
+
primaryPhone: '0101111' + randomNumber,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
it('유저 생성', async () => {
|
|
44
|
+
const userId = await m2mClient.createUser(testUser);
|
|
45
|
+
expect(userId).toBeDefined();
|
|
46
|
+
testUserId = userId;
|
|
47
|
+
});
|
|
48
|
+
it('토큰 발급', async () => {
|
|
49
|
+
await m2mClient.fetchAccessToken();
|
|
50
|
+
});
|
|
51
|
+
it('유저 정보 수정', async () => {
|
|
52
|
+
await m2mClient.updateUserClientInfo(testUserId);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=m2m-client.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"m2m-client.spec.js","sourceRoot":"","sources":["../../../client/__tests__/m2m-client.spec.ts"],"names":[],"mappings":";;AACA,6CAAsD;AACtD,2CAA8C;AAC9C,2DAA8C;AAE9C,0BAA6F;AAC7F,uCAA0E;AAC1E,2CAA+C;AAE/C,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC1C,IAAI,SAAyB,CAAC;IAC9B,IAAI,QAAoB,CAAC;IACzB,IAAI,UAAU,GAAY,cAAc,CAAC;IACzC,IAAI,UAAU,GAAY,uBAAuB,CAAC;IAClD,SAAS,CAAC,KAAK,IAAI,EAAE;QACjB,MAAM,MAAM,GAAkB,MAAM,cAAI,CAAC,mBAAmB,CAAC;YACzD,OAAO,EAAE;gBACL,qBAAY,CAAC,OAAO,CAAC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BAAoB,CAAC,UAAU,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const config_1 = require("@nestjs/config");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const token_1 = require("../../token");
|
|
8
|
+
describe('OAuthClient', () => {
|
|
9
|
+
let oauthClient;
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
const testingModule = await testing_1.Test.createTestingModule({
|
|
12
|
+
imports: [
|
|
13
|
+
config_1.ConfigModule.forRoot({
|
|
14
|
+
envFilePath: `env/.env.${process.env.NODE_ENV}`,
|
|
15
|
+
isGlobal: true,
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
18
|
+
providers: [
|
|
19
|
+
{
|
|
20
|
+
provide: __1.LogtoLoggerServiceToken,
|
|
21
|
+
useClass: common_1.ConsoleLogger
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
provide: __1.OAuthClientToken,
|
|
25
|
+
useClass: __1.OAuthClient
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
provide: token_1.LogtoTokenVerifierToken,
|
|
29
|
+
useClass: token_1.LogtoTokenVerifier
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
}).compile();
|
|
33
|
+
oauthClient = testingModule.get(__1.OAuthClientToken);
|
|
34
|
+
});
|
|
35
|
+
it('로그인/ 회원가입을 위한 로그인 페이지 요청 URI 생성', () => {
|
|
36
|
+
const uri = oauthClient.getSignInURI(__1.SignInType.Admin);
|
|
37
|
+
expect(uri).toContain('prompt=login');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=oauth-client.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-client.spec.js","sourceRoot":"","sources":["../../../client/__tests__/oauth-client.spec.ts"],"names":[],"mappings":";;AAAA,6CAAuC;AACvC,0BAAwF;AACxF,2CAA8C;AAC9C,2CAA+C;AAC/C,uCAA0E;AAE1E,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IACzB,IAAI,WAAwB,CAAC;IAE7B,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,aAAa,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;YACjD,OAAO,EAAE;gBACL,qBAAY,CAAC,OAAO,CAAC;oBACnB,WAAW,EAAE,YAAY,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;oBAC/C,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;YACH,SAAS,EAAE;gBACP;oBACI,OAAO,EAAE,2BAAuB;oBAChC,QAAQ,EAAE,sBAAa;iBAC1B;gBACD;oBACI,OAAO,EAAE,oBAAgB;oBACzB,QAAQ,EAAE,eAAW;iBACxB;gBACD;oBACI,OAAO,EAAE,+BAAuB;oBAChC,QAAQ,EAAE,0BAAkB;iBAC/B;aACJ;SACJ,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,WAAW,GAAG,aAAa,CAAC,GAAG,CAAc,oBAAgB,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QAEvC,MAAM,GAAG,GAAG,WAAW,CAAC,YAAY,CAAC,cAAU,CAAC,KAAK,CAAC,CAAC;QAEvD,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type LogtoConfig = {
|
|
2
|
+
endpoint: string;
|
|
3
|
+
appId: string;
|
|
4
|
+
grantType: GrantType;
|
|
5
|
+
appSecret: string;
|
|
6
|
+
scopes?: string[];
|
|
7
|
+
resources?: string[];
|
|
8
|
+
prompt?: Prompt;
|
|
9
|
+
includeReservedScopes?: boolean;
|
|
10
|
+
redirectUri?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare enum Prompt {
|
|
13
|
+
None = "none",
|
|
14
|
+
Consent = "consent",
|
|
15
|
+
Login = "login"
|
|
16
|
+
}
|
|
17
|
+
export declare enum GrantType {
|
|
18
|
+
AuthorizationCode = "authorization_code",
|
|
19
|
+
ClientCredentials = "client_credentials",
|
|
20
|
+
RefreshToken = "refresh_token"
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GrantType = exports.Prompt = void 0;
|
|
4
|
+
var Prompt;
|
|
5
|
+
(function (Prompt) {
|
|
6
|
+
Prompt["None"] = "none";
|
|
7
|
+
Prompt["Consent"] = "consent";
|
|
8
|
+
Prompt["Login"] = "login";
|
|
9
|
+
})(Prompt || (exports.Prompt = Prompt = {}));
|
|
10
|
+
var GrantType;
|
|
11
|
+
(function (GrantType) {
|
|
12
|
+
GrantType["AuthorizationCode"] = "authorization_code";
|
|
13
|
+
GrantType["ClientCredentials"] = "client_credentials";
|
|
14
|
+
GrantType["RefreshToken"] = "refresh_token";
|
|
15
|
+
})(GrantType || (exports.GrantType = GrantType = {}));
|
|
16
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../client/config.ts"],"names":[],"mappings":";;;AA4DA,IAAY,MAIX;AAJD,WAAY,MAAM;IACd,uBAAa,CAAA;IACb,6BAAmB,CAAA;IACnB,yBAAe,CAAA;AACnB,CAAC,EAJW,MAAM,sBAAN,MAAM,QAIjB;AAUD,IAAY,SAIX;AAJD,WAAY,SAAS;IACjB,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,2CAA8B,CAAA;AAClC,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./config"), exports);
|
|
18
|
+
__exportStar(require("./m2m-client"), exports);
|
|
19
|
+
__exportStar(require("./oauth-client"), exports);
|
|
20
|
+
__exportStar(require("./logto-login-session"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+CAA6B;AAC7B,iDAA+B;AAC/B,wDAAsC;AACtC,0CAAwB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { LoggerService } from "@nestjs/common";
|
|
2
|
+
import { AxiosResponse } from "axios";
|
|
3
|
+
import { OAuthClient, SignInType } from "./oauth-client";
|
|
4
|
+
export declare const LogtoLoginSessionToken: unique symbol;
|
|
5
|
+
export declare class LogtoLoginSession {
|
|
6
|
+
private readonly apiUrl;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
private readonly oauthClient;
|
|
9
|
+
private readonly apiRestTemplate;
|
|
10
|
+
constructor(apiUrl: string, logger: LoggerService, oauthClient: OAuthClient);
|
|
11
|
+
createSignInSession(signInType: SignInType): Promise<{
|
|
12
|
+
response: AxiosResponse | undefined;
|
|
13
|
+
state: string;
|
|
14
|
+
}>;
|
|
15
|
+
experienceSignIn(cookie: string): Promise<any>;
|
|
16
|
+
verificationPassword(cookie: string, dto: {
|
|
17
|
+
identifier: {
|
|
18
|
+
type: string;
|
|
19
|
+
value: string;
|
|
20
|
+
};
|
|
21
|
+
password: string;
|
|
22
|
+
}): Promise<any>;
|
|
23
|
+
identify(cookie: string, verificationId: string): Promise<any>;
|
|
24
|
+
submit(cookie: string): Promise<any>;
|
|
25
|
+
redirectToConsent(redirectTo: string, cookie: string): Promise<AxiosResponse>;
|
|
26
|
+
consent(cookie: string): Promise<any>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.LogtoLoginSession = exports.LogtoLoginSessionToken = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const oauth_client_1 = require("./oauth-client");
|
|
19
|
+
const types_1 = require("./types");
|
|
20
|
+
exports.LogtoLoginSessionToken = Symbol.for("LogtoLoginSession");
|
|
21
|
+
let LogtoLoginSession = class LogtoLoginSession {
|
|
22
|
+
constructor(apiUrl, logger, oauthClient) {
|
|
23
|
+
this.apiUrl = apiUrl;
|
|
24
|
+
this.logger = logger;
|
|
25
|
+
this.oauthClient = oauthClient;
|
|
26
|
+
this.apiRestTemplate = new types_1.LogtoOAuthRESTTemplate(this.logger, apiUrl);
|
|
27
|
+
}
|
|
28
|
+
async createSignInSession(signInType) {
|
|
29
|
+
const { uri, state } = this.oauthClient.getSignInURI(signInType);
|
|
30
|
+
const response = await axios_1.default.get(uri, {
|
|
31
|
+
maxRedirects: 0,
|
|
32
|
+
validateStatus: (status) => status >= 200 && status <= 400,
|
|
33
|
+
withCredentials: true,
|
|
34
|
+
});
|
|
35
|
+
return { response, state };
|
|
36
|
+
}
|
|
37
|
+
async experienceSignIn(cookie) {
|
|
38
|
+
try {
|
|
39
|
+
const response = await this.apiRestTemplate.put(`/experience`, { interactionEvent: 'SignIn' }, {
|
|
40
|
+
headers: {
|
|
41
|
+
'Content-Type': 'application/json',
|
|
42
|
+
Cookie: cookie,
|
|
43
|
+
},
|
|
44
|
+
withCredentials: true,
|
|
45
|
+
});
|
|
46
|
+
return response.data;
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
this.logger.error('Failed to start login experience');
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async verificationPassword(cookie, dto) {
|
|
54
|
+
try {
|
|
55
|
+
const response = await this.apiRestTemplate.post(`/experience/verification/password`, {
|
|
56
|
+
identifier: dto.identifier,
|
|
57
|
+
password: dto.password,
|
|
58
|
+
}, {
|
|
59
|
+
headers: { Cookie: cookie, "Accept-Language": 'ko-KR, ko;' },
|
|
60
|
+
withCredentials: true,
|
|
61
|
+
});
|
|
62
|
+
return response.data;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async identify(cookie, verificationId) {
|
|
69
|
+
try {
|
|
70
|
+
const response = await this.apiRestTemplate.post(`/experience/identification`, { verificationId }, {
|
|
71
|
+
headers: { Cookie: cookie },
|
|
72
|
+
withCredentials: true,
|
|
73
|
+
});
|
|
74
|
+
return response.data;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async submit(cookie) {
|
|
81
|
+
try {
|
|
82
|
+
const response = await this.apiRestTemplate.post(`/experience/submit`, {}, {
|
|
83
|
+
headers: { Cookie: cookie },
|
|
84
|
+
withCredentials: true,
|
|
85
|
+
});
|
|
86
|
+
return response.data;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async redirectToConsent(redirectTo, cookie) {
|
|
93
|
+
const response = await axios_1.default.get(redirectTo, {
|
|
94
|
+
maxRedirects: 0,
|
|
95
|
+
validateStatus: (status) => status >= 200 && status <= 400,
|
|
96
|
+
withCredentials: true,
|
|
97
|
+
headers: { Cookie: cookie },
|
|
98
|
+
});
|
|
99
|
+
return response;
|
|
100
|
+
}
|
|
101
|
+
async consent(cookie) {
|
|
102
|
+
try {
|
|
103
|
+
const response = await this.apiRestTemplate.post(`/interaction/consent`, {}, {
|
|
104
|
+
headers: { Cookie: cookie },
|
|
105
|
+
withCredentials: true,
|
|
106
|
+
});
|
|
107
|
+
return response.data;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
exports.LogtoLoginSession = LogtoLoginSession;
|
|
115
|
+
exports.LogtoLoginSession = LogtoLoginSession = __decorate([
|
|
116
|
+
(0, common_1.Injectable)(),
|
|
117
|
+
__metadata("design:paramtypes", [String, Object, oauth_client_1.OAuthClient])
|
|
118
|
+
], LogtoLoginSession);
|
|
119
|
+
//# sourceMappingURL=logto-login-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,W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YAAY,EAAE,CAAC;YACf,cAAc,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,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"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LoggerService } from "@nestjs/common";
|
|
2
|
+
import { LogtoM2MConfig } from "./config";
|
|
3
|
+
import { LogtoTokenVerifier } from "../token";
|
|
4
|
+
import { LogtoRole, LogtoRoleResponse, LogtoUser, LogtoUserResponse } from "./types";
|
|
5
|
+
import { p3Values } from "point3-common-tool";
|
|
6
|
+
export declare const LogtoM2MClientToken: unique symbol;
|
|
7
|
+
export declare class LogtoM2MClient {
|
|
8
|
+
private readonly config;
|
|
9
|
+
private readonly tokenVerifier;
|
|
10
|
+
private readonly logger;
|
|
11
|
+
private logtoConfig;
|
|
12
|
+
private accessToken?;
|
|
13
|
+
private readonly authRestTemplate;
|
|
14
|
+
private readonly apiRestTemplate;
|
|
15
|
+
constructor(config: LogtoM2MConfig, tokenVerifier: LogtoTokenVerifier, logger: LoggerService);
|
|
16
|
+
fetchAccessToken(): Promise<void>;
|
|
17
|
+
fetchAccessTokenByPAT(pat: string): Promise<{
|
|
18
|
+
accessToken: string;
|
|
19
|
+
}>;
|
|
20
|
+
private getAccessToken;
|
|
21
|
+
getRoles(): Promise<LogtoRoleResponse[]>;
|
|
22
|
+
getRoleByName(name: string): Promise<LogtoRoleResponse>;
|
|
23
|
+
createRole(role: LogtoRole): Promise<LogtoRoleResponse>;
|
|
24
|
+
assignRoleToUser(userId: string, roleId: string): Promise<void>;
|
|
25
|
+
createUser(user: LogtoUser): Promise<string>;
|
|
26
|
+
updateUserClientInfo(userId: string, clientId?: string): Promise<void>;
|
|
27
|
+
getUser(id: string): Promise<LogtoUserResponse>;
|
|
28
|
+
getUserByUsername(username: string): Promise<LogtoUserResponse>;
|
|
29
|
+
suspendUser(userId: string): Promise<LogtoUserResponse>;
|
|
30
|
+
deleteUser(userId: string): Promise<void>;
|
|
31
|
+
deleteUserRole(userId: string, roleId: string): Promise<void>;
|
|
32
|
+
unsuspendUser(userId: string): Promise<LogtoUserResponse>;
|
|
33
|
+
sendVerificationCode(identifier: p3Values.PhoneNumber | p3Values.Email): Promise<void>;
|
|
34
|
+
verifyCode(identifier: p3Values.PhoneNumber | p3Values.Email, code: string): Promise<void>;
|
|
35
|
+
updateUserPassword(userId: string, password: string): Promise<LogtoUserResponse>;
|
|
36
|
+
}
|
|
37
|
+
export declare function generatePhoneNumberWithCountryCode(countryCode: string, phoneNumber: string): string;
|
|
@@ -0,0 +1,196 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LogtoM2MClient = exports.LogtoM2MClientToken = void 0;
|
|
13
|
+
exports.generatePhoneNumberWithCountryCode = generatePhoneNumberWithCountryCode;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const config_1 = require("./config");
|
|
16
|
+
const token_1 = require("../token");
|
|
17
|
+
const types_1 = require("./types");
|
|
18
|
+
const point3_common_tool_1 = require("point3-common-tool");
|
|
19
|
+
const errors_1 = require("../errors");
|
|
20
|
+
exports.LogtoM2MClientToken = Symbol.for("LogtoM2MClient");
|
|
21
|
+
let LogtoM2MClient = class LogtoM2MClient {
|
|
22
|
+
constructor(config, tokenVerifier, logger) {
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.tokenVerifier = tokenVerifier;
|
|
25
|
+
this.logger = logger;
|
|
26
|
+
this.logtoConfig = {
|
|
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,
|
|
33
|
+
};
|
|
34
|
+
this.authRestTemplate = new types_1.LogtoOAuthRESTTemplate(this.logger, this.logtoConfig.endpoint);
|
|
35
|
+
this.authRestTemplate.setBasic(this.logtoConfig.appId, this.logtoConfig.appSecret);
|
|
36
|
+
this.apiRestTemplate = new types_1.LogtoOAuthRESTTemplate(this.logger, config.apiUrl);
|
|
37
|
+
}
|
|
38
|
+
async fetchAccessToken() {
|
|
39
|
+
const params = new URLSearchParams();
|
|
40
|
+
params.set('grant_type', this.logtoConfig.grantType);
|
|
41
|
+
params.set('scope', this.logtoConfig.scopes.join(' '));
|
|
42
|
+
params.set('resource', this.logtoConfig.resources.join(' '));
|
|
43
|
+
const response = await this.authRestTemplate.post('/token', params.toString(), {
|
|
44
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
45
|
+
});
|
|
46
|
+
const { access_token, expires_in } = response.data;
|
|
47
|
+
const payload = await this.tokenVerifier.verifyToken(access_token);
|
|
48
|
+
this.accessToken = new token_1.AccessToken(payload.sub, access_token, expires_in);
|
|
49
|
+
this.apiRestTemplate.setBearer(access_token);
|
|
50
|
+
}
|
|
51
|
+
async fetchAccessTokenByPAT(pat) {
|
|
52
|
+
try {
|
|
53
|
+
const parameters = new URLSearchParams();
|
|
54
|
+
parameters.set("grant_type", "urn:ietf:params:oauth:grant-type:token-exchange");
|
|
55
|
+
parameters.set("scope", this.logtoConfig.scopes.join(" "));
|
|
56
|
+
parameters.set("resource", this.logtoConfig.resources.join(" "));
|
|
57
|
+
parameters.set("subject_token", pat);
|
|
58
|
+
parameters.set("subject_token_type", "urn:logto:token-type:personal_access_token");
|
|
59
|
+
const response = await this.authRestTemplate.post(`${this.logtoConfig.endpoint}/token`, parameters.toString(), {
|
|
60
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
61
|
+
});
|
|
62
|
+
console.log(response);
|
|
63
|
+
return {
|
|
64
|
+
accessToken: response.data["access_token"],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw new Error(pat);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async getAccessToken() {
|
|
72
|
+
if (!this.accessToken || this.accessToken.isExpired()) {
|
|
73
|
+
await this.fetchAccessToken();
|
|
74
|
+
}
|
|
75
|
+
return this.accessToken.token;
|
|
76
|
+
}
|
|
77
|
+
async getRoles() {
|
|
78
|
+
await this.getAccessToken();
|
|
79
|
+
const response = await this.apiRestTemplate.get('/roles');
|
|
80
|
+
return response.data;
|
|
81
|
+
}
|
|
82
|
+
async getRoleByName(name) {
|
|
83
|
+
await this.getAccessToken();
|
|
84
|
+
const params = new URLSearchParams();
|
|
85
|
+
params.set('search.name', name);
|
|
86
|
+
const response = await this.apiRestTemplate.get(`/roles?${params.toString()}`);
|
|
87
|
+
return response.data[0];
|
|
88
|
+
}
|
|
89
|
+
async createRole(role) {
|
|
90
|
+
await this.getAccessToken();
|
|
91
|
+
const body = {
|
|
92
|
+
name: role.name,
|
|
93
|
+
description: role.description,
|
|
94
|
+
type: role.type,
|
|
95
|
+
};
|
|
96
|
+
const response = await this.apiRestTemplate.post('/roles', body);
|
|
97
|
+
if (response instanceof point3_common_tool_1.axiosAdapter.ValidationError) {
|
|
98
|
+
if (response.code === 'role.name_in_use') {
|
|
99
|
+
this.logger.error(`이미 존재하는 역할: ${response.code}`, this.constructor.name);
|
|
100
|
+
return this.getRoleByName(role.name);
|
|
101
|
+
}
|
|
102
|
+
throw response;
|
|
103
|
+
}
|
|
104
|
+
return response.data;
|
|
105
|
+
}
|
|
106
|
+
async assignRoleToUser(userId, roleId) {
|
|
107
|
+
await this.getAccessToken();
|
|
108
|
+
const body = { roleIds: [roleId] };
|
|
109
|
+
await this.apiRestTemplate.post(`/users/${userId}/roles`, body);
|
|
110
|
+
this.logger.log(`사용자에 역할 할당: ${userId}`, this.constructor.name);
|
|
111
|
+
}
|
|
112
|
+
async createUser(user) {
|
|
113
|
+
await this.getAccessToken();
|
|
114
|
+
if (user.username && user.primaryEmail && user.password && user.name) {
|
|
115
|
+
user.passwordAlgorithm = user.passwordAlgorithm ?? types_1.LogtoPasswordAlgorithm.Argon2i;
|
|
116
|
+
const response = await this.apiRestTemplate.post('/users', user);
|
|
117
|
+
return response.data.id;
|
|
118
|
+
}
|
|
119
|
+
this.logger.error(`필수 필드 누락`, this.constructor.name);
|
|
120
|
+
throw new errors_1.UserMissingRequiredFieldsError();
|
|
121
|
+
}
|
|
122
|
+
async updateUserClientInfo(userId, clientId) {
|
|
123
|
+
await this.getAccessToken();
|
|
124
|
+
await this.apiRestTemplate.patch(`/users/${userId}`, {
|
|
125
|
+
customData: { clientId },
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async getUser(id) {
|
|
129
|
+
await this.getAccessToken();
|
|
130
|
+
const response = await this.apiRestTemplate.get(`/users/${id}`);
|
|
131
|
+
return response.data;
|
|
132
|
+
}
|
|
133
|
+
async getUserByUsername(username) {
|
|
134
|
+
await this.getAccessToken();
|
|
135
|
+
const params = new URLSearchParams();
|
|
136
|
+
params.set('search.username', username);
|
|
137
|
+
params.set('mode.username', 'exact');
|
|
138
|
+
const response = await this.apiRestTemplate.get(`/users?${params.toString()}`);
|
|
139
|
+
return response.data[0];
|
|
140
|
+
}
|
|
141
|
+
async suspendUser(userId) {
|
|
142
|
+
await this.getAccessToken();
|
|
143
|
+
const response = await this.apiRestTemplate.patch(`/users/${userId}/is-suspended`, { isSuspended: true });
|
|
144
|
+
return response.data;
|
|
145
|
+
}
|
|
146
|
+
async deleteUser(userId) {
|
|
147
|
+
await this.getAccessToken();
|
|
148
|
+
await this.apiRestTemplate.delete(`/users/${userId}`);
|
|
149
|
+
}
|
|
150
|
+
async deleteUserRole(userId, roleId) {
|
|
151
|
+
await this.getAccessToken();
|
|
152
|
+
await this.apiRestTemplate.delete(`/roles/${roleId}/users/${userId}`);
|
|
153
|
+
}
|
|
154
|
+
async unsuspendUser(userId) {
|
|
155
|
+
await this.getAccessToken();
|
|
156
|
+
const response = await this.apiRestTemplate.patch(`/users/${userId}/is-suspended`, { isSuspended: false });
|
|
157
|
+
return response.data;
|
|
158
|
+
}
|
|
159
|
+
async sendVerificationCode(identifier) {
|
|
160
|
+
await this.getAccessToken();
|
|
161
|
+
const method = identifier instanceof types_1.VerificationMethodType.email
|
|
162
|
+
? "email"
|
|
163
|
+
: "phone";
|
|
164
|
+
await this.apiRestTemplate.post('/verification-codes', {
|
|
165
|
+
[method]: identifier.toString(),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
async verifyCode(identifier, code) {
|
|
169
|
+
await this.getAccessToken();
|
|
170
|
+
const method = identifier instanceof types_1.VerificationMethodType.email
|
|
171
|
+
? 'email'
|
|
172
|
+
: 'phone';
|
|
173
|
+
await this.apiRestTemplate.post(`/verification-codes/verify`, {
|
|
174
|
+
[method]: identifier.toString(),
|
|
175
|
+
verificationCode: code,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
async updateUserPassword(userId, password) {
|
|
179
|
+
await this.getAccessToken();
|
|
180
|
+
const response = await this.apiRestTemplate.patch(`/users/${userId}/password`, { password });
|
|
181
|
+
return response.data;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
exports.LogtoM2MClient = LogtoM2MClient;
|
|
185
|
+
exports.LogtoM2MClient = LogtoM2MClient = __decorate([
|
|
186
|
+
(0, common_1.Global)(),
|
|
187
|
+
(0, common_1.Injectable)(),
|
|
188
|
+
__metadata("design:paramtypes", [Object, token_1.LogtoTokenVerifier, Object])
|
|
189
|
+
], LogtoM2MClient);
|
|
190
|
+
function generatePhoneNumberWithCountryCode(countryCode, phoneNumber) {
|
|
191
|
+
if (phoneNumber.startsWith('0')) {
|
|
192
|
+
phoneNumber = phoneNumber.slice(1);
|
|
193
|
+
}
|
|
194
|
+
return `${countryCode}${phoneNumber}`;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=m2m-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;A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AAY;QAEZ,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAE5B,MAAM,MAAM,GACR,UAAU,YAAY,8BAAsB,CAAC,KAAK;YAC9C,CAAC,CAAC,OAAO;YACT,CAAC,CAAC,OAAO,CAAC;QAElB,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,4BAA4B,EAAE;YAC1D,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,EAAE;YAC/B,gBAAgB,EAAE,IAAI;SACzB,CAAC,CAAC;IACP,CAAC;IAOD,KAAK,CAAC,kBAAkB,CAAC,MAAc,EAAE,QAAgB;QACrD,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,KAAK,CAC7C,UAAU,MAAM,WAAW,EAC3B,EAAE,QAAQ,EAAE,CACf,CAAC;QACF,OAAO,QAAQ,CAAC,IAAI,CAAC;IACzB,CAAC;CACJ,CAAA;AA7VY,wCAAc;yBAAd,cAAc;IAF1B,IAAA,eAAM,GAAE;IACR,IAAA,mBAAU,GAAE;6CAY2B,0BAAkB;GAX7C,cAAc,CA6V1B;AAQD,SAAgB,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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LoggerService } from "@nestjs/common";
|
|
2
|
+
import { LogtoOAuthConfig } from "./config";
|
|
3
|
+
export declare const OAuthClientToken = "OAuthClient";
|
|
4
|
+
export declare class OAuthClient {
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private logtoConfig;
|
|
8
|
+
private logtoRestTemplate;
|
|
9
|
+
static readonly prefix: string;
|
|
10
|
+
constructor(config: LogtoOAuthConfig, logger: LoggerService);
|
|
11
|
+
getSignInURI(signInType: SignInType): {
|
|
12
|
+
uri: string;
|
|
13
|
+
state: string;
|
|
14
|
+
};
|
|
15
|
+
getSignOutURI(): Promise<string>;
|
|
16
|
+
fetchTokenByAuthorizationCode(code: string): Promise<{
|
|
17
|
+
accessToken: string;
|
|
18
|
+
idToken: string;
|
|
19
|
+
}>;
|
|
20
|
+
revokeToken(token: string): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export declare enum SignInType {
|
|
23
|
+
Admin = "admin",
|
|
24
|
+
Dashboard = "dashboard"
|
|
25
|
+
}
|