-
Notifications
You must be signed in to change notification settings - Fork 50
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
Added support for ECIDs passed via the adobe_mc query string parameter. Added appendIdentityToUrl command to enable cross-domain identity sharing. #862
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
07d5b7d
parse the query string for adobe_mc and add unit tests
jonsnyder 797cc4b
Fixes after testing in the sandbox
jonsnyder 7add720
Create functional tests and fix hasIdentity error in getIdentity payload
jonsnyder 09a80bc
Merge remote-tracking branch 'origin/main' into queryStringIdentity
jonsnyder 1277323
Add a few more functional tests, extract common functionality from tests
jonsnyder 803f5c0
Add logging to AddQueryStringIdentityToPayload, add additional unit t…
jonsnyder 1684ecf
Add better comments. Use constant for TTL
jonsnyder c1d7318
Write a different AMCV cookie if the ECID has changed. Add failing te…
jonsnyder 0af3b6f
Add comment and update logging message from code review
jonsnyder acb4eb2
Add appendIdentityToUrl command with updated unit tests and sandbox.
jonsnyder cf9dbb5
Add functional tests for appendIdentityToUrl, round the timestamp
jonsnyder 63838f5
Use alloyio2.com as the cross-domain link
jonsnyder e6b85f5
revert sandbox index.html back to original config
jonsnyder 08c7d13
Remove unresolved promise error in test for Firefox and Safari
jonsnyder bdf2051
Add test from mobile team url
jonsnyder 5638ee3
Add idOverwriteEnabled config
jonsnyder 69a1340
Merge remote-tracking branch 'origin/main' into queryStringIdentity2
jonsnyder d394a21
Skip test that is waiting on Konductor changes
jonsnyder 136f6e6
set idOverwriteEnabled default to false, Updated sandbox to help with…
jonsnyder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2022 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
import React, { useState } from "react"; | ||
|
||
const getIdentity = setIdentity => () => { | ||
window.alloy("getIdentity", { namespaces: ["ECID"] }).then(function(result) { | ||
if (result.identity) { | ||
console.log( | ||
"Sandbox: Get Identity command has completed.", | ||
result.identity.ECID | ||
); | ||
setIdentity(result.identity.ECID); | ||
} else { | ||
console.log( | ||
"Sandbox: Get Identity command has completed but no identity was provided in the result (possibly due to lack of consent)." | ||
); | ||
setIdentity("No Identity"); | ||
} | ||
}); | ||
}; | ||
|
||
const appendIdentityToUrl = event => { | ||
const url = event.target.href; | ||
event.preventDefault(); | ||
window.alloy("appendIdentityToUrl", { url }).then(({ url }) => { | ||
document.location = url; | ||
}); | ||
}; | ||
|
||
export default function Identity() { | ||
const [identity, setIdentity] = useState(""); | ||
|
||
return ( | ||
<div> | ||
<h1>Identity</h1> | ||
<section> | ||
<h2>Get Identity</h2> | ||
<div> | ||
<button onClick={getIdentity(setIdentity)}>Get ECID</button> | ||
<h3>{identity}</h3> | ||
</div> | ||
</section> | ||
<section> | ||
<a href="https://alloyio2.com/identity" onClick={appendIdentityToUrl}> | ||
Cross domain linked identity. | ||
</a> | ||
</section> | ||
</div> | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/components/Identity/appendIdentityToUrl/appendIdentityToUrlOptionsValidator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Copyright 2022 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
|
||
import { objectOf, string } from "../../../utils/validation"; | ||
/** | ||
* Verifies user provided event options. | ||
* @param {*} options The user event options to validate | ||
* @returns {*} Validated options | ||
*/ | ||
export default objectOf({ | ||
url: string() | ||
.required() | ||
.nonEmpty() | ||
}) | ||
.required() | ||
.noUnknownFields(); |
30 changes: 30 additions & 0 deletions
30
src/components/Identity/appendIdentityToUrl/injectAppendIdentityToUrl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright 2022 Adobe. All rights reserved. | ||
This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. You may obtain a copy | ||
of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under | ||
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language | ||
governing permissions and limitations under the License. | ||
*/ | ||
const URL_REGEX = /^([^?#]*)(\??[^#]*)(#?.*)$/; | ||
|
||
const getSeparator = queryString => { | ||
if (queryString === "") { | ||
return "?"; | ||
} | ||
if (queryString === "?") { | ||
return ""; | ||
} | ||
return "&"; | ||
}; | ||
|
||
export default ({ dateProvider, orgId }) => (ecid, url) => { | ||
const ts = Math.round(dateProvider().getTime() / 1000); | ||
const adobemc = encodeURIComponent(`TS=${ts}|MCMID=${ecid}|MCORGID=${orgId}`); | ||
const [, location, queryString, fragment] = url.match(URL_REGEX); | ||
const separator = getSeparator(queryString); | ||
return `${location}${queryString}${separator}adobe_mc=${adobemc}${fragment}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/components/Identity/injectAddQueryStringIdentityToPayload.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Example: adobe_mc=TS%3D1641432103%7CMCMID%3D77094828402023918047117570965393734545%7CMCORGID%3DFAF554945B90342F0A495E2C%40AdobeOrg | ||
// Decoded: adobe_mc=TS=1641432103|MCMID=77094828402023918047117570965393734545|MCORGID=FAF554945B90342F0A495E2C@AdobeOrg | ||
|
||
import { queryString } from "../../utils"; | ||
import queryStringIdentityParam from "../../constants/queryStringIdentityParam"; | ||
import ecidNamespace from "../../constants/ecidNamespace"; | ||
|
||
const LINK_TTL_SECONDS = 300; // 5 minute link time to live | ||
|
||
export default ({ | ||
locationSearch, | ||
dateProvider, | ||
orgId, | ||
logger, | ||
idOverwriteEnabled | ||
}) => payload => { | ||
if (payload.hasIdentity(ecidNamespace)) { | ||
// don't overwrite a user provided ecid identity | ||
return; | ||
} | ||
|
||
const parsedQueryString = queryString.parse(locationSearch); | ||
const queryStringValue = parsedQueryString[queryStringIdentityParam]; | ||
if (queryStringValue === undefined) { | ||
return; | ||
} | ||
|
||
const properties = queryStringValue.split("|").reduce((memo, keyValue) => { | ||
const [key, value] = keyValue.split("="); | ||
memo[key] = value; | ||
return memo; | ||
}, {}); | ||
// We are using MCMID and MCORGID to be compatible with Visitor. | ||
const ts = parseInt(properties.TS, 10); | ||
const mcmid = properties.MCMID; | ||
const mcorgid = properties.MCORGID; | ||
|
||
if ( | ||
// When TS is not specified or not a number, the following inequality returns false. | ||
// All inequalities with NaN variables are false. | ||
dateProvider().getTime() / 1000 <= ts + LINK_TTL_SECONDS && | ||
mcorgid === orgId && | ||
mcmid | ||
) { | ||
logger.info( | ||
`Found valid ECID identity ${mcmid} from the adobe_mc query string parameter.` | ||
); | ||
payload.addIdentity(ecidNamespace, { | ||
id: mcmid | ||
}); | ||
if (idOverwriteEnabled) { | ||
payload.mergeQuery({ | ||
identity: { | ||
overwriteExisting: true | ||
} | ||
}); | ||
} | ||
} else { | ||
logger.info("Detected invalid or expired adobe_mc query string parameter."); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think true is the right default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think false might be a safer bet since that’s how it behaves today in Visitor.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s ask Mitch though