Skip to content

Commit

Permalink
Check if SSO is Enabled Before Login Platform Account (#174)
Browse files Browse the repository at this point in the history
Check if SSO is enabled before login platform account.
  • Loading branch information
serenayanbolt authored Aug 3, 2023
1 parent 82b4084 commit 9dfb1bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cartridges/int_bolt_embedded_sfra/cartridge/controllers/Bolt.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var Resource = require('dw/web/Resource');
var BasketMgr = require('dw/order/BasketMgr');
var Transaction = require('dw/system/Transaction');
var CustomerMgr = require('dw/customer/CustomerMgr');
var Site = require('dw/system/Site');

// Script includes
var LogUtils = require('~/cartridge/scripts/util/boltLogUtils');
Expand All @@ -22,6 +23,7 @@ var log = LogUtils.getLogger('Bolt');
server.get('FetchOAuthToken', server.middleware.https, function (req, res, next) {
var response = oAuth.fetchNewToken(req.querystring.code, req.querystring.scope);
var returnObject = {};
var isSSOEnabled = Site.getCurrent().getCustomPreferenceValue('boltEnableSSO');

if (response.status === HttpResult.OK) {
returnObject.accessToken = response.result.access_token;
Expand All @@ -32,11 +34,16 @@ server.get('FetchOAuthToken', server.middleware.https, function (req, res, next)
// store OAuth token expire time in milliseconds, 1000 -> ONE_SECOND
session.privacy.boltOAuthTokenExpire = response.result.expires_in * 1000
+ new Date().getTime();
var currentBasket = BasketMgr.getCurrentOrNewBasket();
Transaction.wrap(function () {
currentBasket.custom.boltEmbeddedAccountsTokens = JSON.stringify(response.result);
});
account.loginOrCreatePlatformAccount(response.result.id_token);

// login platform account use the id token in response if sso enabled
if (isSSOEnabled) {
var currentBasket = BasketMgr.getCurrentOrNewBasket();
Transaction.wrap(function () {
currentBasket.custom.boltEmbeddedAccountsTokens = JSON.stringify(response.result);
});
account.loginOrCreatePlatformAccount(response.result.id_token);
}

account.removeFallbackLogoutCookie(res);
log.info('fetching oauth token succeeded');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ exports.removeFallbackLogoutCookie = function (res) {
};

/**
* Used for SSO login from checkout step
* Create a new external authenticated account if no existing account and login the shopper to SFCC platform
* @param {string} idToken - A JWT token issued when the request includes the scope open_id
*/
Expand Down

0 comments on commit 9dfb1bc

Please sign in to comment.