#Next-auth error with Battlenet provider - [SIGNIN_OAUTH_ERROR]

8 messages · Page 1 of 1 (latest)

wheat ginkgo
#

I'm getting the error [next-auth][error][SIGNIN_OAUTH_ERROR] . When I looked it up on the Next-auth website, it stated this:

SIGNIN_OAUTH_ERROR
This error occurs during the redirection to the authorization URL of the OAuth provider. Possible causes:

1. Cookie handling Either PKCE code verifier or the generation of the CSRF token hash in the internal state failed.
If set, check your cookies configuration, and make sure the browser is not blocking/restricting cookies.

2. OAuth misconfiguration
Please check your OAuth provider and make sure your URLs and other options are correctly set.

If you are using an OAuth v1 provider, check your OAuth v1 provider settings, especially the OAuth token and OAuth token secret.

3. openid-client version mismatch
If you are seeing expected 200 OK with body but no body was returned, it might have happened due to openid-client (which is a dependency we rely on) node version mismatch. For instance, openid-client requires >=14.2.0 for lts/fermium and has similar limits for the other versions. For the full list of the compatible node versions please see package.json.

The second option seem to align the most to my problem, but I'm stuck.

This is the code:

rapid mantleBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

wheat ginkgo
#

[...nextauth].ts

import { DefaultSession, NextAuthOptions, User, getServerSession } from "next-auth";
import BattleNetProvider from "next-auth/providers/battlenet"
import NextAuth from "next-auth/next";

declare module 'next-auth' {
    /**
     * Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
     */
    interface Session { 
      accessToken?: string
    }
  }

export const authConfig: NextAuthOptions = {
    providers: [
        BattleNetProvider({
            clientId: process.env.BNET_CLIENT_ID!,
            clientSecret: process.env.BNET_CLIENT_SECRET!,
            issuer: "https://www.battlenet.com.cn/oauth"
        })
    ],
    callbacks: {
    async jwt({ token, account }) {
        // Persist the OAuth access_token to the token right after signin
        if (account) {
        token.accessToken = account.access_token
        }
        return token
    },
    async session({ session, token, user } )  {
        // Send properties to the client, like an access_token from a provider.
        session.accessToken = token.accessToken as string
        return session
    }
    },
    secret: process.env.JWT_SECRET
}

export default NextAuth(authConfig)

login-btn.tsx


import { useSession, signIn, signOut } from "next-auth/react"
export default function Component() {
    const { data: session } = useSession()
    if (session) {
        return (
            <>
                Signed in as {session.user!.email} <br />
                <button onClick={() => signOut()}>Sign out</button>
            </>
        )
    }
    return (
        <>
            Not signed in <br />
            <button onClick={() => signIn()}>Sign in</button>
        </>
    )
}
#

_app.tsx

import '@/styles/globals.css'
import type { AppProps } from 'next/app'
import { SessionProvider } from 'next-auth/react'

export default function App({ Component, pageProps: { session, ...pageProps } }: AppProps) {
  return <SessionProvider session={session}>
    <Component {...pageProps} />
  </SessionProvider>
}
wheat ginkgo
#

All I need is a template for the battlenet provider for next-auth. They seem to use some sort of authorize URI https://oauth.battle.net/authorize, but I'm unclear on how to use it.

wise coyote
#

Try using battle.net's well-known to find their oidc-configuration file

wheat ginkgo
wise coyote
#

Use OIDC with Next-Auth and point the url in the provider to Battle.net's OIDC config file at <root-url>/.well-known/<oidc-config>