nextauthjs / nextauthjs/next-auth

SignIn with Azure Active Directory redirects with OAuthAccountNotLinked

Open
#6,784 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

providers triage
Dominant language
TypeScript
Stars
28.4k
Forks
4k
PR merge metrics
No merged PRs in 30d

Description

Provider type

Azure Active Directory

Environment

System:
OS: Windows 10 10.0.19045
CPU: (8) x64 Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
Memory: 794.18 MB / 7.84 GB
Binaries:
Node: 16.14.0 - C:\Program Files\nodejs\node.EXE
npm: 8.5.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: 110.0.5481.104
Edge: Spartan (44.19041.1266.0), Chromium (110.0.1587.50)
Internet Explorer: 11.0.19041.1566
npmPackages:
next: 12.2.4 => 12.2.4
next-auth: ^4.10.3 => 4.10.3
react: "^18.2.0"=> 18.0.17

Reproduction URL

private

Describe the issue

We have implemented two providers Email link and Azure Active Directory. Adapter is Prisma and db PostgreSQL.

The Email link is working ok.
Azure-ad provider is failing when trying to signIn with a user that has previously signed in using email link. The URI is redirected with error=OAuthAccountNotLinked.

Debug mode shows:

  • Azure-ad returning ok result
  • Adapter calling adapter_getUserByAccount and adapter_getUserByEmail and the process stops with error=OAuthAccountNotLinked redirection.
How to reproduce
  1. Sign in with a user via magic link -> user record will be generated in db
  2. Sign out
  3. Sign in the same user(email) via azure-ad
Expected behavior

Azure-ad sign-in should be compatible with email link mechanism as stated here:

https://next-auth.js.org/faq#when-i-sign-in-with-another-account-with-the-same-email-address-why-are-accounts-not-linked-automatically

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the flow from the issue: sign in with an email link, sign out, then use Azure Active Directory with the same email. Trace the adapter_getUserByAccount and adapter_getUserByEmail calls that lead to OAuthAccountNotLinked; no source files or tests are named. Done means the documented expected behavior is verified with the Prisma/PostgreSQL adapter.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, postgresql, typescript
Domain
authentication, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.