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

compat fix: PKCE loadMeta will fallback to local storage #399

Merged
merged 2 commits into from
Jun 12, 2020

Conversation

aarongranick-okta
Copy link
Contributor

This fixes an error involving PKCE flow and the signin widget. In version 3.1.2 of okta-auth-js the PKCE meta storage was changed to use sessionStorage. However, current and older versions of the signin widget which are bundled with an older version of okta-auth-js will store the PKCE meta in local storage. This will cause an error: The redirectUri passed to /authorize must also be passed to /token on callback. The underlying cause is that PKCE meta was not found in storage and an empty codeVerifier was passed to the /token endpoint.

This PR adds logic to read from local storage if the meta cannot be found in session storage. This will provide compatibility for older versions of okta-auth-js including the bundled version within the signin widget.

Additionally, this PR adds logic so that if the meta cannot be found in either session or local storage, an error will be thrown. This will avoid making a call to /token with an empty codeVerifier which causes the misleading error about "redirectUri"

@@ -40,7 +40,8 @@ storageUtil.browserHasSessionStorage = function() {
};

storageUtil.getPKCEStorage = function(options) {
if (storageUtil.browserHasSessionStorage()) {
options = options || {};
if (!options.preferLocalStorage && storageUtil.browserHasSessionStorage()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

// Verify the Meta
if (!obj.codeVerifier) {
// If meta is not valid, try reading from localStorage.
// This is for compatibility with older versions of the signin widget.
Copy link
Contributor

@swiftone swiftone Jun 12, 2020

Choose a reason for hiding this comment

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

I'd love a Jira ticket reference here so someone could look up the specifics and know if the comment still applies.

@aarongranick-okta aarongranick-okta merged commit 4e87c37 into master Jun 12, 2020
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.

2 participants