moleculer-iam
Version:
Centralized IAM module for moleculer. Including a certified OIDC provider and an Identity provider for user profile, credentials, and custom claims management. Custom claims could be defined/updated by declarative schema which contains claims validation a
67 lines • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.kakaoProviderConfiguration = void 0;
const passport_kakao_1 = require("passport-kakao");
const error_1 = require("../../proxy/error");
// Kakao is not a OIDC provider; openid scope not supported
// phone scope not supported
exports.kakaoProviderConfiguration = {
clientID: "",
clientSecret: "",
scope: "profile account_email",
strategy: (options, verify) => {
return new passport_kakao_1.Strategy(options, verify);
},
callback: async (args) => {
const { accessToken, refreshToken, idp, profile, logger, scope } = args;
// gather federation metadata
const metadata = { federation: { kakao: { id: profile.id } } };
// gather claims
const claims = {
name: profile._json.kakao_account.profile.nickname,
picture: profile._json.kakao_account.profile.profile_image_url,
email: profile._json.kakao_account.email,
email_verified: profile._json.kakao_account.is_email_verified,
};
if (!claims.email) {
throw new error_1.OIDCProviderProxyErrors.FederationRequestWithoutEmailPayload();
}
if (!claims.email_verified) {
delete claims.email_verified;
}
if (!claims.picture) {
delete claims.picture;
}
// find existing account
let identity = await idp.find({ metadata });
// connect the identity which has same email address
if (!identity && claims.email) {
identity = await idp.find({ claims: { email: claims.email } });
// if (identity) {
// const oldClaims = await identity.claims("userinfo", "email");
// if (!oldClaims.email_verified) {
// throw new IAMErrors.UnexpectedError("cannot federate an existing account with non-verified email address");
// }
// }
}
// update or create
const upsertScopes = idp.claims.mandatoryScopes;
if (identity) {
if (await identity.isSoftDeleted()) {
throw new error_1.OIDCProviderProxyErrors.FederationRequestForDeletedAccount();
}
await identity.updateMetadata(metadata);
await identity.updateClaims(claims, upsertScopes, undefined, true);
return identity;
}
else {
return idp.create({
metadata,
claims,
credentials: {},
scope: upsertScopes,
}, undefined, true);
}
},
};
//# sourceMappingURL=kakao.js.map