@arc-publishing/sdk-identity
Version:
JS Identity SDK for working with Identity API
132 lines • 6.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.signOnSwgUser = exports.googleSignOn = exports.deprecationMessage = void 0;
var tslib_1 = require("tslib");
var socialSignOn_1 = require("./socialSignOn");
var socialSignOnTypes_1 = require("./socialSignOnTypes");
var initGoogleLogin_1 = require("./initGoogleLogin");
var identity_1 = tslib_1.__importDefault(require("./identity"));
exports.deprecationMessage = 'Legacy Google Sign In will be deprecated on Dec 31, 2022. Use the new Arc Identity & Sign In With Google SDKs.';
var googleSignOn = function (googleUser) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var authInstance, googleUser_1, e, e_1;
var _a;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
console.error(exports.deprecationMessage);
if (googleUser) {
return [2, signOnWithGoogleUser(googleUser)];
}
_b.label = 1;
case 1:
_b.trys.push([1, 7, , 8]);
if (!(0, socialSignOnTypes_1.isLegacyGoogleSetting)(identity_1.default._google)) return [3, 5];
if (!!identity_1.default._google.authInstance) return [3, 3];
return [4, (0, initGoogleLogin_1.getGoogleAuthInstance)()];
case 2:
_b.sent();
_b.label = 3;
case 3:
authInstance = identity_1.default._google.authInstance;
if (authInstance && authInstance.isSignedIn.get()) {
return [2, signOnWithGoogleUser(authInstance.currentUser.get())];
}
return [4, ((_a = identity_1.default._google.authInstance) === null || _a === void 0 ? void 0 : _a.signIn({
prompt: 'select_account'
}))];
case 4:
googleUser_1 = _b.sent();
return [2, signOnWithGoogleUser(googleUser_1)];
case 5:
e = new Error('[Arc Identity SDK] - This method will only work with the legacy Google Sign In. Discontinue use of this method.');
console.error(e);
throw e;
case 6: return [3, 8];
case 7:
e_1 = _b.sent();
throw e_1;
case 8: return [2];
}
});
}); };
exports.googleSignOn = googleSignOn;
var signOnSwgUser = function (_a) {
var idToken = _a.idToken, swgSubscriptionTokenResponse = _a.swgSubscriptionTokenResponse;
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var currentUser, idToken_1, e;
var _b, _c;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
console.error(exports.deprecationMessage);
if (!idToken) return [3, 1];
return [2, (0, socialSignOn_1.socialLogin)('google', { credentials: idToken })];
case 1:
if (!swgSubscriptionTokenResponse) return [3, 2];
identity_1.default.userIdentity = {
uuid: swgSubscriptionTokenResponse.profileId,
accessToken: swgSubscriptionTokenResponse.accessToken,
refreshToken: swgSubscriptionTokenResponse.refreshToken
};
return [2, identity_1.default.heartbeat()];
case 2: return [4, (0, initGoogleLogin_1.getGoogleAuthInstance)()];
case 3:
_d.sent();
if ((0, socialSignOnTypes_1.isLegacyGoogleSetting)(identity_1.default._google)) {
if ((_b = identity_1.default._google.authInstance) === null || _b === void 0 ? void 0 : _b.isSignedIn.get()) {
currentUser = (_c = identity_1.default._google.authInstance) === null || _c === void 0 ? void 0 : _c.currentUser.get();
idToken_1 = currentUser.getAuthResponse().id_token;
return [2, (0, socialSignOn_1.socialLogin)('google', { credentials: idToken_1 })];
}
else {
throw new Error('[Arc Identity SDK] - No google user logged in.');
}
}
else {
e = new Error('[Arc Identity SDK] - This method will only work with the legacy Google Sign In. Discontinue use of this method.');
console.error(e);
throw e;
}
_d.label = 4;
case 4: return [2];
}
});
});
};
exports.signOnSwgUser = signOnSwgUser;
var signOnWithGoogleUser = function (googleUser) {
console.error(exports.deprecationMessage);
var googleIdToken = googleUser.getAuthResponse().id_token;
if ((0, socialSignOnTypes_1.isLegacyGoogleSetting)(identity_1.default._google)) {
return (0, socialSignOn_1.socialLogin)('google', {
credentials: googleIdToken
})
.then(function (userIdentity) {
if ((0, socialSignOnTypes_1.isLegacyGoogleSetting)(identity_1.default._google)) {
if (identity_1.default._google.onSuccess) {
identity_1.default._google.onSuccess();
}
return userIdentity;
}
else {
throw new Error('[Arc Identity SDK] - This method will only work with the legacy Google Sign In. Discontinue use of this method.');
}
})
.catch(function (e) {
if ((0, socialSignOnTypes_1.isLegacyGoogleSetting)(identity_1.default._google)) {
if (identity_1.default._google.onFailure) {
identity_1.default._google.onFailure();
}
throw e;
}
else {
throw new Error('[Arc Identity SDK] - This method will only work with the legacy Google Sign In. Discontinue use of this method.');
}
});
}
else {
throw new Error('[Arc Identity SDK] - This method will only work with the legacy Google Sign In. Discontinue use of this method.');
}
};
exports.default = exports.googleSignOn;
//# sourceMappingURL=googleSignOn.js.map