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

[Bug]: Discord OAuth not working #439

Closed
1 of 2 tasks
VozdyxActions opened this issue Jun 12, 2024 · 4 comments
Closed
1 of 2 tasks

[Bug]: Discord OAuth not working #439

VozdyxActions opened this issue Jun 12, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@VozdyxActions
Copy link

VozdyxActions commented Jun 12, 2024

🐛 Describe the Bug

When I tried to sign in via Discord OAuth i got OAuthCallback error

🔍 Steps to Reproduce

  1. Set up this environment variables for Discord OAuth
OAUTH_ALLOW_DANGEROUS_EMAIL_LINKING: "true"
OAUTH_ID: "1006863453895524403"
OAUTH_SECRET: "no-no-no"
OAUTH_ACCESS_TOKEN_URL: "https://discord.com/api/oauth2/token"
OAUTH_AUTHORIZATION_URL: "https://discord.com/api/oauth2/authorize?client_id=1006863453895524403&response_type=code&redirect_uri=https%3A%2F%2Fmy.awesome.domain%2Fapi%2Fauth%2Fcallback%2Foauth&scope=email+identify"
OAUTH_USER_INFO: "https://discord.com/api/users/@me"
  1. Set up this redirect uri on Discord Developers Portal
https://my.awesome.domain/api/auth/callback/oauth
  1. Try sign in via Discord OAuth
  2. Get OAuthCallback error

🔧 Deployment Type

  • Docker
  • Standalone

✨ Expected Behavior

Signed in

📋 ZTNET Logs

~ztnet> docker logs ztnet
Creating .env file...
Applying migrations to the database...
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "ztnet", schema "public" at "postgres:5432"

31 migrations found in prisma/migrations


No pending migrations to apply.
npm notice
npm notice New minor version of npm available! 10.7.0 -> 10.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.1
npm notice To update run: npm install -g [email protected]
npm notice
Migrations applied successfully!
Seeding the database...
Environment variables loaded from .env
Running seed command `ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts` ...
Seeding:: User Options complete!
Seeding:: Updating user ID complete!

🌱  The seed command has been executed.
Database seeded successfully!
Executing command
   ▲ Next.js 14.1.4
   - Local:        http:https://9b85f645c023:3000
   - Network:      http:https://172.31.255.4:3000

 ✓ Ready in 184ms
[next-auth][error][OAUTH_CALLBACK_ERROR]
https://next-auth.js.org/errors#oauth_callback_error invalid_grant (Invalid "redirect_uri" in request.) {
  error: OPError: invalid_grant (Invalid "redirect_uri" in request.)
      at processResponse (/app/node_modules/openid-client/lib/helpers/process_response.js:38:13)
      at Client.grant (/app/node_modules/openid-client/lib/client.js:1354:22)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async Client.oauthCallback (/app/node_modules/openid-client/lib/client.js:620:24)
      at async oAuthCallback (/app/node_modules/next-auth/core/lib/oauth/callback.js:111:16)
      at async Object.callback (/app/node_modules/next-auth/core/routes/callback.js:52:11)
      at async AuthHandler (/app/node_modules/next-auth/core/index.js:208:28)
      at async NextAuthApiHandler (/app/node_modules/next-auth/next/index.js:22:19)
      at async NextAuth._args$ (/app/node_modules/next-auth/next/index.js:108:14)
      at async K (/app/node_modules/next/dist/compiled/next-server/pages-api.runtime.prod.js:20:16545) {
    name: 'OAuthCallbackError',
    code: undefined
  },
  providerId: 'oauth',
  message: 'invalid_grant (Invalid "redirect_uri" in request.)'
}

🖼 Screenshots

image

@VozdyxActions VozdyxActions added the bug Something isn't working label Jun 12, 2024
@VozdyxActions
Copy link
Author

VozdyxActions commented Jun 12, 2024

The error occurs because in request body to receive the Discord OAuth token you need to pass the used redirect_uri.
In my case it's https://my.awesome.domain/api/auth/callback/oauth
image

Read more about Discord OAuth
https://discord.com/developers/docs/topics/oauth2#authorization-code-grant

@sinamics
Copy link
Owner

tested discord oauth on my prod server, and everything works fine on my end.

  • Does your NEXTAUTH_URL reflectes the redirect domain used in discord?
  • Did you copy the Generated URL from Discord Oauth page? It should be pasted in ztnet OAUTH_AUTHORIZATION_URL

@VozdyxActions
Copy link
Author

  • Does your NEXTAUTH_URL reflectes the redirect domain used in discord?
  • Yes
  • Did you copy the Generated URL from Discord Oauth page? It should be pasted in ztnet OAUTH_AUTHORIZATION_URL
  • Yes

@VozdyxActions
Copy link
Author

VozdyxActions commented Jun 13, 2024

  • Does your NEXTAUTH_URL reflectes the redirect domain used in discord?

My mistake was that I specified http instead of https in NEXTAUTH_URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants