@openauth/kakao
Version:
Kakao OAuth library
80 lines (79 loc) • 2.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.KakaoOAuth = void 0;
const core_1 = require("@openauth/core");
class KakaoOAuth extends core_1.OAuth20 {
constructor() {
super(...arguments);
Object.defineProperty(this, "authRequestUri", {
enumerable: true,
configurable: true,
writable: true,
value: "https://kauth.kakao.com/oauth/authorize"
});
Object.defineProperty(this, "accessTokenRequestUri", {
enumerable: true,
configurable: true,
writable: true,
value: "https://kauth.kakao.com/oauth/token"
});
Object.defineProperty(this, "userProfileUri", {
enumerable: true,
configurable: true,
writable: true,
value: "https://kapi.kakao.com/v2/user/me"
});
Object.defineProperty(this, "jwksUri", {
enumerable: true,
configurable: true,
writable: true,
value: "https://kauth.kakao.com/.well-known/jwks.json"
});
Object.defineProperty(this, "jwtIssuer", {
enumerable: true,
configurable: true,
writable: true,
value: "https://kauth.kakao.com"
});
Object.defineProperty(this, "scopes", {
enumerable: true,
configurable: true,
writable: true,
value: []
});
Object.defineProperty(this, "scopeSeparator", {
enumerable: true,
configurable: true,
writable: true,
value: ","
});
Object.defineProperty(this, "requestAccessTokenMethod", {
enumerable: true,
configurable: true,
writable: true,
value: "get"
});
}
createErrorFromHttpClientError(e) {
if (e.data !== null && typeof e.data === "object" && "msg" in e.data) {
const { msg: message, ...extra } = e.data;
return new core_1.OAuthError(message, e.message, extra);
}
return super.createErrorFromHttpClientError(e);
}
mapDataToUserProfile(data) {
const nickname = data.properties?.nickname ?? data.kakao_account?.profile?.nickname;
const picture = data.properties?.profile_image ?? data.kakao_account?.profile?.profile_image_url;
return {
id: `${data.id}`,
...(data.kakao_account?.email && { email: data.kakao_account?.email }),
...(typeof data.kakao_account?.is_email_verified === "boolean" &&
{ emailVerified: data.kakao_account?.is_email_verified }),
...(nickname && { nickname }),
...(picture && { picture }),
...(data.kakao_account?.gender && { gender: data.kakao_account?.gender }),
raw: data,
};
}
}
exports.KakaoOAuth = KakaoOAuth;