Next.js Discord

Discord Forum

Unexpected ID Token returned (Custom Next-Auth Provider) V5

Answered
Catla posted this in #help-forum
Open in Discord
Avatar
CatlaOP
import DiscordProvider from "next-auth/providers/discord";
import type { OAuth2Config } from "@auth/core/providers"

import type { NextAuthConfig } from "next-auth"

interface UserProfile {
    sub: string;
};

export default {
    providers: [
        DiscordProvider({
            clientId: process.env.DISCORD_CLIENT_ID as string,
            clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
            authorization: {
                params: {
                    scope: 'identify'
                }
            },
        }),
        {
            id: 'roblox',
            name: 'Roblox',
            type: "oauth",
            clientId: process.env.ROBLOX_ID as string,
            clientSecret: process.env.ROBLOX_SECRET as string,
            issuer: 'https://apis.roblox.com/oauth/',
            authorization: { params: { scope: 'openid', redirect_uri: 'https://rolinker.net/auth' } },
            client: {
                authorization_signed_response_alg: 'ES256',
                id_token_signed_response_alg: 'ES256',
            },
            checks: ['pkce', 'state'],
            token: 'https://apis.roblox.com/oauth/v1/token',
            userinfo: 'https://apis.roblox.com/oauth/v1/userinfo',
            profile(profile) {
                return {
                    type: 'roblox',
                    id: profile.sub
                }
            }
        } satisfies OAuth2Config<UserProfile>
    ],
} satisfies NextAuthConfig
Answered by Catla
Resolved. Changed type to oidc. Added a redirectProxyUrl, and removed my checks because redirect will add state by default
View full answer

2 Replies

Avatar
CatlaOP
I am receiving the following error on the above code:

[auth][error] CallbackRouteError: Read more at https://errors.authjs.dev#callbackrouteerror
[auth][cause]: OperationProcessingError: Unexpected ID Token returned, use processAuthorizationCodeOpenIDResponse() for OpenID Connect callback processing
    at Module.processAuthorizationCodeOAuth2Response (webpack-internal:///(rsc)/./node_modules/oauth4webapi/build/index.js:1182:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async handleOAuth (webpack-internal:///(rsc)/./node_modules/next-auth/node_modules/@auth/core/lib/actions/callback/oauth/callback.js:85:18)
    at async Module.callback (webpack-internal:///(rsc)/./node_modules/next-auth/node_modules/@auth/core/lib/actions/callback/index.js:33:41)
    at async AuthInternal (webpack-internal:///(rsc)/./node_modules/next-auth/node_modules/@auth/core/lib/index.js:42:24)
    at async Auth (webpack-internal:///(rsc)/./node_modules/next-auth/node_modules/@auth/core/index.js:123:29)
    at async D:\rolinker\rl-app\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:63809
    at async eU.execute (D:\rolinker\rl-app\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:53964)
    at async eU.handle (D:\rolinker\rl-app\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:65062)
    at async doRender (D:\rolinker\rl-app\node_modules\next\dist\server\base-server.js:1333:42)
    at async cacheEntry.responseCache.get.routeKind (D:\rolinker\rl-app\node_modules\next\dist\server\base-server.js:1543:40)
    at async DevServer.renderToResponseWithComponentsImpl (D:\rolinker\rl-app\node_modules\next\dist\server\base-server.js:1463:28)
    at async DevServer.renderPageComponent 
[auth][details]: {
  "provider": "roblox"
}


I'm stumped. I don't know if it helps but here is the Roblox Oauth2 Documentation:

https://create.roblox.com/docs/en-us/cloud/reference/oauth2
Avatar
CatlaOP
Resolved. Changed type to oidc. Added a redirectProxyUrl, and removed my checks because redirect will add state by default
Answer