UNPKG

@openauth/kakao

Version:
56 lines 2.72 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.KakaoOAuth = void 0; const core_1 = require("@openauth/core"); const kakao_client_1 = require("./kakao-client"); class KakaoOAuth extends core_1.OAuth2 { apiBaseUri() { return 'https://kapi.kakao.com/v2'; } authRequestUri() { return 'https://kauth.kakao.com/oauth/authorize'; } accessTokenRequestUri() { return 'https://kauth.kakao.com/oauth/token'; } mapDataToAccessTokenResponse(body) { return { accessToken: body.access_token, tokenType: body.token_type, expiresIn: body.expires_in, refreshToken: body.refresh_token, refreshTokenExpiresIn: body.refresh_token_expires_in, }; } createClient(accessToken) { return new kakao_client_1.KakaoClient({ baseUri: this.apiBaseUri(), fetch: this._fetch, accessToken, }); } getAuthUser(accessToken) { var _a, _b, _c, _d, _e, _f, _g, _h, _j; return __awaiter(this, void 0, void 0, function* () { const { data } = yield this.getClient(accessToken).getUserMe(); return { id: `${data.id}`, email: (_a = data.kakao_account) === null || _a === void 0 ? void 0 : _a.email, nickname: (_c = (_b = data.properties) === null || _b === void 0 ? void 0 : _b.nickname) !== null && _c !== void 0 ? _c : (_e = (_d = data.kakao_account) === null || _d === void 0 ? void 0 : _d.profile) === null || _e === void 0 ? void 0 : _e.nickname, avatar: (_g = (_f = data.properties) === null || _f === void 0 ? void 0 : _f.profile_image) !== null && _g !== void 0 ? _g : (_j = (_h = data.kakao_account) === null || _h === void 0 ? void 0 : _h.profile) === null || _j === void 0 ? void 0 : _j.profile_image_url, raw: data, }; }); } } exports.KakaoOAuth = KakaoOAuth; //# sourceMappingURL=kakao-oauth.js.map