UNPKG

@point3/logto-module

Version:

포인트3 내부 logto Authentication 모듈입니다

119 lines 4.66 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LogtoLoginSession = exports.LogtoLoginSessionToken = void 0; const common_1 = require("@nestjs/common"); const axios_1 = __importDefault(require("axios")); const oauth_client_1 = require("./oauth-client"); const types_1 = require("./types"); exports.LogtoLoginSessionToken = Symbol.for("LogtoLoginSession"); let LogtoLoginSession = class LogtoLoginSession { constructor(apiUrl, logger, oauthClient) { this.apiUrl = apiUrl; this.logger = logger; this.oauthClient = oauthClient; this.apiRestTemplate = new types_1.LogtoOAuthRESTTemplate(this.logger, apiUrl); } async createSignInSession(signInType) { const { uri, state } = this.oauthClient.getSignInURI(signInType); const response = await axios_1.default.get(uri, { maxRedirects: 0, validateStatus: (status) => status >= 200 && status <= 400, withCredentials: true, }); return { response, state }; } async experienceSignIn(cookie) { try { const response = await this.apiRestTemplate.put(`/experience`, { interactionEvent: 'SignIn' }, { headers: { 'Content-Type': 'application/json', Cookie: cookie, }, withCredentials: true, }); return response.data; } catch (error) { this.logger.error('Failed to start login experience'); throw error; } } async verificationPassword(cookie, dto) { try { const response = await this.apiRestTemplate.post(`/experience/verification/password`, { identifier: dto.identifier, password: dto.password, }, { headers: { Cookie: cookie, "Accept-Language": 'ko-KR, ko;' }, withCredentials: true, }); return response.data; } catch (error) { throw error; } } async identify(cookie, verificationId) { try { const response = await this.apiRestTemplate.post(`/experience/identification`, { verificationId }, { headers: { Cookie: cookie }, withCredentials: true, }); return response.data; } catch (error) { throw error; } } async submit(cookie) { try { const response = await this.apiRestTemplate.post(`/experience/submit`, {}, { headers: { Cookie: cookie }, withCredentials: true, }); return response.data; } catch (error) { throw error; } } async redirectToConsent(redirectTo, cookie) { const response = await axios_1.default.get(redirectTo, { maxRedirects: 0, validateStatus: (status) => status >= 200 && status <= 400, withCredentials: true, headers: { Cookie: cookie }, }); return response; } async consent(cookie) { try { const response = await this.apiRestTemplate.post(`/interaction/consent`, {}, { headers: { Cookie: cookie }, withCredentials: true, }); return response.data; } catch (error) { throw error; } } }; exports.LogtoLoginSession = LogtoLoginSession; exports.LogtoLoginSession = LogtoLoginSession = __decorate([ (0, common_1.Injectable)(), __metadata("design:paramtypes", [String, Object, oauth_client_1.OAuthClient]) ], LogtoLoginSession); //# sourceMappingURL=logto-login-session.js.map