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

Add JWT support #754

Merged
merged 13 commits into from
May 7, 2021
Merged

Add JWT support #754

merged 13 commits into from
May 7, 2021

Conversation

cea2aj
Copy link
Member

@cea2aj cea2aj commented May 6, 2021

Add iframe JWT support which is enabled when useJWT is true in global config

For iframe experiences, add iframe-jwt.js (along with prod and staging versions) which provide an initAnswersFrameJWT function. The answers experience will load once initAnswersFrameJWT is called.

For non-iframe experiences, initAnswersJWT must be called rather than initAnswersFrameJWT

The next PR will ensure that the apiKey from the jambo injected data will not appear in the output of any builds.

This PR does not include JWT overlay support.

J=SLAP-1118
TEST=manual

Test iframe-jwt.js and see that the page doesn't load until initAnswersFrame is ran. Test supplying valid and invalid tokens. Test navigating between pages and refreshing the page. Test that if the answers experience with useJWT=true is loaded directly (not through the iframe), and error message appears in the console. Smoke test the non-iframe experience and the the overlay integration with useJWT=false. Test JWT locally and on SGS. Test in a cross-domain manner with a local test site which points to an answers experience on SGS which is running this branch. On SGS, test iframe-jwt-prod.js and iframe-jwt-staging.js

Test JWT on non-iframe experiences.

layouts/html.hbs Outdated Show resolved Hide resolved
layouts/html.hbs Outdated Show resolved Hide resolved
script/core.hbs Outdated Show resolved Hide resolved
@cea2aj cea2aj requested a review from oshi97 May 6, 2021 23:02
Copy link
Collaborator

@tmeyer2115 tmeyer2115 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question I had, and this may be more for @rosiegrant , how would JWT support work for someone using the Theme without an iFrame integration? I'm assuming that's a use case we should support. Would they override core.hbs to invoke the token getter somewhere and pass that to the ANSWERS.init?

static/js/iframe-common.js Outdated Show resolved Hide resolved
layouts/html.hbs Outdated
@@ -123,6 +123,10 @@
window.iframeLoaded = new Promise(resolve => {
iframeLoadedResolve = resolve;
});
let iframeJWTResolve;
window.iframeJWT = new Promise(resolve => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own edification, why do we need to wrap the iframeJWTResolve in a Promise here? Could we just set a function on the window in core.hbs, not wrap that in a Promise, and invoke it in the onMessage?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

html.hbs executes before core.hbs, right? I want to prevent the possibility of that function trying to be called before it is put on the window

@cea2aj
Copy link
Member Author

cea2aj commented May 7, 2021

One question I had, and this may be more for @rosiegrant , how would JWT support work for someone using the Theme without an iFrame integration? I'm assuming that's a use case we should support. Would they override core.hbs to invoke the token getter somewhere and pass that to the ANSWERS.init?

Updated so that non-iframe experiences can be loaded with JWT with initAnswersJWT

script/core.hbs Outdated
{{#if global_config.useJWT}}
const jwtNotProvidedTimeout = setTimeout(() => {
console.warn(
'A JWT is required to initialize this Answers experience because "useJWT" is set to true.\n' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to say something along the lines of "a JWT has not been received within 5s of page load"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I think that makes sense. I'll check with Rose on this because that was the error message originally requested in the spec

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I didn't realize the error message was from the spec, thought it was just a nice thing you came up with

@tmeyer2115 tmeyer2115 self-requested a review May 7, 2021 17:48
@cea2aj cea2aj requested review from tmeyer2115 and oshi97 May 7, 2021 18:08
@cea2aj cea2aj merged commit abea750 into feature/jwt-support May 7, 2021
@cea2aj cea2aj changed the title Add iframe JWT support Add JWT support May 7, 2021
cea2aj added a commit that referenced this pull request Jun 1, 2021
Add JWT support which is enabled when useJWT is true in global config

For iframe experiences, add iframe-jwt.js (along with prod and staging versions) which provide an `initAnswersFrameJWT` function. The answers experience will load once `initAnswersFrameJWT` is called.

For non-iframe experiences, `initAnswersJWT` must be called rather than `initAnswersFrameJWT`

The next PR will ensure that the apiKey from the jambo injected data will not appear in the output of any builds.

This PR does not include JWT overlay support.

J=SLAP-1118
TEST=manual

Test iframe-jwt.js and see that the page doesn't load until initAnswersFrame is ran. Test supplying valid and invalid tokens. Test navigating between pages and refreshing the page. Test that if the answers experience with `useJWT=true` is loaded directly (not through the iframe), and error message appears in the console. Smoke test the non-iframe experience and the the overlay integration with `useJWT=false`.  Test JWT locally and on SGS. Test in a cross-domain manner with a local test site which points to an answers experience on SGS which is running this branch. On SGS, test iframe-jwt-prod.js and iframe-jwt-staging.js

Test JWT on non-iframe experiences.
cea2aj added a commit that referenced this pull request Jun 1, 2021
Add JWT support which is enabled when useJWT is true in global config

For iframe experiences, add iframe-jwt.js (along with prod and staging versions) which provide an `initAnswersFrameJWT` function. The answers experience will load once `initAnswersFrameJWT` is called.

For non-iframe experiences, `initAnswersJWT` must be called rather than `initAnswersFrameJWT`

The next PR will ensure that the apiKey from the jambo injected data will not appear in the output of any builds.

This PR does not include JWT overlay support.

J=SLAP-1118
TEST=manual

Test iframe-jwt.js and see that the page doesn't load until initAnswersFrame is ran. Test supplying valid and invalid tokens. Test navigating between pages and refreshing the page. Test that if the answers experience with `useJWT=true` is loaded directly (not through the iframe), and error message appears in the console. Smoke test the non-iframe experience and the the overlay integration with `useJWT=false`.  Test JWT locally and on SGS. Test in a cross-domain manner with a local test site which points to an answers experience on SGS which is running this branch. On SGS, test iframe-jwt-prod.js and iframe-jwt-staging.js

Test JWT on non-iframe experiences.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants