Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identity Link - Use ats library for retrieving envelope #4077

Merged
merged 3 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions modules/identityLinkSystem.js → modules/identityLinkIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,37 @@ export const identityLinkSubmodule = {
}
// use protocol relative urls for http or https
const url = `https://api.rlcdn.com/api/identity/envelope?pid=${configParams.pid}`;

return function (callback) {
ajax(url, response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
// if ats library is initialised, use it to retrieve envelope. If not use standard third party endpoint
if (window.ats) {
return function(callback) {
window.ats.retrieveEnvelope(function (envelope) {
if (envelope) {
callback(JSON.parse(envelope).envelope);
} else {
getEnvelope(url, callback);
}
}
callback(responseObj.envelope);
}, undefined, { method: 'GET' });
});
}
} else {
return function (callback) {
getEnvelope(url, callback);
}
}
}
};
}
// return envelope from third party endpoint
function getEnvelope(url, callback) {
ajax(url, response => {
let responseObj;
if (response) {
try {
responseObj = JSON.parse(response);
} catch (error) {
utils.logError(error);
}
}
callback(responseObj.envelope);
}, undefined, {method: 'GET', withCredentials: true});
}

submodule('userId', identityLinkSubmodule);
2 changes: 1 addition & 1 deletion test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as utils from 'src/utils';
import {unifiedIdSubmodule} from 'modules/userId/unifiedIdSystem';
import {pubCommonIdSubmodule} from 'modules/userId/pubCommonIdSystem';
import {id5IdSubmodule} from 'modules/id5IdSystem';
import {identityLinkSubmodule} from 'modules/identityLinkSystem';
import {identityLinkSubmodule} from 'modules/identityLinkIdSystem';
let assert = require('chai').assert;
let expect = require('chai').expect;
const EXPIRED_COOKIE_DATE = 'Thu, 01 Jan 1970 00:00:01 GMT';
Expand Down