Hebilicious / authjs-nuxt

AuthJS edge-compatible authentication Nuxt module.
https://authjs-nuxt.pages.dev/
MIT License
253 stars 28 forks source link

Cannot finish the setup with Auth0 #159

Closed alxpereira closed 9 months ago

alxpereira commented 9 months ago

Environment

Reproduction

Nuxt3 setup with authjs nuxt plugin.

auth/[...].ts setup as below

import Auth0Provider from "@auth/core/providers/auth0";
import type { AuthConfig } from "@auth/core/types";
import { NuxtAuthHandler } from "#auth";

const runtimeConfig = useRuntimeConfig();

export const authOptions: AuthConfig = {
  secret: runtimeConfig.authJs.secret,
  theme: {
    logo: "https://nuxt.com/assets/design-kit/logo/icon-green.png",
  },
  providers: [
    Auth0Provider({
      clientId: process.env.AUTH0_CLIENT_ID,
      clientSecret: process.env.AUTH0_SECRET,
      issuer: process.env.AUTH0_BASEURL,
      wellKnown: `https://${process.env.AUTH0_DOMAIN}/.well-known/openid-configuration`,
      authorization: {
        url: `https://${process.env.AUTH0_DOMAIN}/authorize`,
        params: { scope: "openid profile email" },
      },
    }),
  ],
};

export default NuxtAuthHandler(authOptions, runtimeConfig);

Describe the bug

The login page is starting properly, but got this error on callback. It tried to test a lot of possible configurations in the Provider setup, but nothing goes properly.

OperationProcessingError: "response" is not a conform Authorization Server Metadata response

Any idea ?

Additional context

No response

Logs

No response

outofthisworld commented 9 months ago

Likely a configuration issue. Check none of your env variables are incorrect or coming as empty and that you've provided all the none optional data. Additionally, check your client configuration in auth0.

@alxpereira

You have the following config (issuer and wellKnown using different env vars for domain)

 issuer: process.env.AUTH0_BASEURL,
 wellKnown: `https://${process.env.AUTH0_DOMAIN}/.well-known/openid-configuration`

However within the auth0 provider well known is specified like this:

wellKnown: ${options.issuer}/.well-known/openid-configuration

Maybe just try specifying just the issuer and copy the example provided by auth0 exactly.

alxpereira commented 9 months ago

Thanks, I found the issue, indeed the issuer / wellKnow settings were in collision, the documentation was unclear.

For the record, here is my final (working) setting :

export const authOptions: AuthConfig = {
  secret: runtimeConfig.authJs.secret,
  theme: {
    logo: "https://nuxt.com/assets/design-kit/logo/icon-green.png",
  },
  providers: [
    Auth0Provider({
      clientId: process.env.AUTH0_CLIENT_ID,
      clientSecret: process.env.AUTH0_SECRET,
      issuer: `https://${process.env.AUTH0_DOMAIN}`,
      authorization: {
        url: `https://${process.env.AUTH0_DOMAIN}/authorize`,
        params: { scope: "openid profile email" },
      },
    }),
  ],
};