Skip to content

fix(clerk-js): Fix FAPI initiated redirect flow for OAuth2 IDP flow with email_link verification#2677

Merged
mzhong9723 merged 1 commit intomainfrom
mz/core-1567-oauth-provider-email-link-verification
Jan 31, 2024
Merged

fix(clerk-js): Fix FAPI initiated redirect flow for OAuth2 IDP flow with email_link verification#2677
mzhong9723 merged 1 commit intomainfrom
mz/core-1567-oauth-provider-email-link-verification

Conversation

@mzhong9723
Copy link
Copy Markdown
Member

@mzhong9723 mzhong9723 commented Jan 29, 2024

Description

For the OAuth2 IDP flow, we should not redirect when the referrer is the sign up url. This way, a second factor can be completed after a first factor like email verification link. Previously, users were being redirected back to FAPI /oauth/authorize prematurely. This change ensures that users will not be redirected as such and have the chance to complete their second factor verification, like phone code.

Fixes CORE-1567

Video of fix below (there's a jump in the middle because I cut out retrieving the email link from my inbox):
https://github.com/clerk/javascript/assets/27433835/63e4ec43-1107-4c90-8ee5-f9196be7210c

Previously, the user would be redirected back to the sign in page without being able to complete sign up.

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Packages affected

  • @clerk/backend
  • @clerk/chrome-extension
  • @clerk/clerk-js
  • @clerk/clerk-expo
  • @clerk/fastify
  • gatsby-plugin-clerk
  • @clerk/localizations
  • @clerk/nextjs
  • @clerk/clerk-react
  • @clerk/remix
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/themes
  • @clerk/types
  • build/tooling/chore

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 29, 2024

🦋 Changeset detected

Latest commit: 575478b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mzhong9723 mzhong9723 requested review from a team and octoper and removed request for a team and octoper January 29, 2024 21:26
Copy link
Copy Markdown
Contributor

@panteliselef panteliselef left a comment

Choose a reason for hiding this comment

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

@mzhong9723 Seems like this was reported for v4 components and we should probably need to backport this PR to v4.

I will help with that once the PR is merged to main. Could we just add a description in the changeset ?

Comment on lines +1 to +3
---
---
Copy link
Copy Markdown
Contributor

@panteliselef panteliselef Jan 30, 2024

Choose a reason for hiding this comment

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

Maybe something like this ?

Suggested change
---
---
---
'@clerk/clerk-js': patch
---
Fix redirect flow for OAuth2 IDP flow with email_link verification.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks @panteliselef, updated the changeset!

Comment thread packages/clerk-js/src/core/clerk.ts Outdated
@@ -1615,9 +1615,11 @@ export class Clerk implements ClerkInterface {
const userSignedIn = this.session;
const signInUrl = this.#environment?.displayConfig.signInUrl;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In ClerkJS both signInUrl and signUpUrl can be injected via ClerkOptions. These ClerkOptions come from CLERK_SIGN_IN_URL in frameworks such as Next.js. The display config settings are left as a fallback and are downplayed in v5.

So for this method, we should pick signInUrl and signUpUrl from ClerkOptions first.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@SokratisVidros updated both sign in and sign up urls to use ClerkOptions first and display config urls as a second fallback option

@mzhong9723 mzhong9723 force-pushed the mz/core-1567-oauth-provider-email-link-verification branch from 37851d3 to 6574d50 Compare January 30, 2024 15:37
@mzhong9723 mzhong9723 force-pushed the mz/core-1567-oauth-provider-email-link-verification branch from 6574d50 to f5e6a4f Compare January 30, 2024 15:41
Comment thread packages/clerk-js/src/core/clerk.ts Outdated

const userSignedIn = this.session;
const signInUrl = this.#environment?.displayConfig.signInUrl;
const signInUrl = this.#options.signInUrl ? this.#options.signInUrl : this.#environment?.displayConfig.signInUrl;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const signInUrl = this.#options.signInUrl ? this.#options.signInUrl : this.#environment?.displayConfig.signInUrl;
const signInUrl = this.#options.signInUrl || this.#environment?.displayConfig.signInUrl;

…ith email_link verification

For the OAuth2 IDP flow, we should not redirect when the referrer is
the sign up url. This way, the second factor can be completed
after a first factor like email verification link. Previously,
users were being redirected back to FAPI /oauth/authorize
prematurely. This change ensures that users will not be
redirected as such and have the chance to complete their second
factor verification, like phone code.
@mzhong9723 mzhong9723 force-pushed the mz/core-1567-oauth-provider-email-link-verification branch from f5e6a4f to 575478b Compare January 31, 2024 14:28
@mzhong9723 mzhong9723 added this pull request to the merge queue Jan 31, 2024
Merged via the queue into main with commit 7503376 Jan 31, 2024
@mzhong9723 mzhong9723 deleted the mz/core-1567-oauth-provider-email-link-verification branch January 31, 2024 15:02
panteliselef pushed a commit that referenced this pull request Feb 1, 2024
…ith email_link verification (#2677)

For the OAuth2 IDP flow, we should not redirect when the referrer is
the sign up url. This way, the second factor can be completed
after a first factor like email verification link. Previously,
users were being redirected back to FAPI /oauth/authorize
prematurely. This change ensures that users will not be
redirected as such and have the chance to complete their second
factor verification, like phone code.

(cherry picked from commit 7503376)
github-merge-queue Bot pushed a commit that referenced this pull request Feb 1, 2024
…ith email_link verification (#2677) (#2702)

For the OAuth2 IDP flow, we should not redirect when the referrer is
the sign up url. This way, the second factor can be completed
after a first factor like email verification link. Previously,
users were being redirected back to FAPI /oauth/authorize
prematurely. This change ensures that users will not be
redirected as such and have the chance to complete their second
factor verification, like phone code.

(cherry picked from commit 7503376)

Co-authored-by: Mary Zhong <mary@clerk.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants