itpropro / nuxt-oidc-auth

OIDC (OpenID connect) focused auth module for Nuxt
https://nuxt.com/modules/nuxt-oidc-auth
MIT License
68 stars 13 forks source link

Token Request Failed - Callback route not found #45

Open mmillican opened 1 month ago

mmillican commented 1 month ago

I am having an issue getting this to run in my Nuxt project using the generic OIDC provider (with AWS Cognito).

The auth flow initializes fine and I get to the Cognito login page fine. When redirected back to the callback page, I get a 500: Token request failed error. Looking at the console logs, I see that its failing to find the route for the callback, even though I have the middleware registered. I have compared everything else I can think of to the playground project in the repository.

[nuxt] error caught during app initialization Error: Page not found: /auth/oidc/callback?

Package versions: Nuxi: ^3.12.0 Nuxt: ^3.12.4 nuxt-oidc-auth: ^0.12.0

Nuxt.config.ts

// https://nuxt.com/docs/api/configuration/nuxt-config
export default {
    modules: [
    "nuxt-oidc-auth",
  ],
    googleFonts: {
        families: {
            Inter: true,
        },
    },
    tailwindcss: {
        jit: true,
    },
  runtimeConfig: {
    public: {
      apiBaseUrl: process.env.API_BASE_URL,
    },
  },
  imports: {
    dirs: ['./utils'],
  },
  oidc: {
    middleware: {
      globalMiddlewareEnabled: true,
    },
    defaultProvider: 'oidc',
    providers: {
      oidc: {
        clientId: '***',
        clientSecret: '***',
        responseType: 'code',
        pkce: true,
        authorizationUrl: 'https://***.auth.us-east-1.amazoncognito.com/oauth2/authorize',
        tokenUrl: 'https://***.auth.us-east-1.amazoncognito.com/oauth2/token',
        userinfoUrl: 'https://***.auth.us-east-1.amazoncognito.com/oauth2/userInfo',
        redirectUri: 'http://localhost:3000/auth/oidc/callback',
        scope: [ 'openid', 'profile' ],
        responseMode: 'query',
      },
    },
  },
  nitro: {
    preset: 'node-server',
    storage: { // Local file system storage for demo purposes
      oidc: {
        driver: 'fs',
        base: 'oidcstorage'
      }
    }
  },
};
DiogoCunhaMoreira commented 1 month ago

If meanwhile you solve this issue please tell us how. I'm also with the same problem and cant figure it out.

Thanks a lot.

MartinVogtFHNW commented 1 month ago

I have the same problem here and would appreciate a solution. The redirect to the IdP and back to the app with the auth code work. But afterwards, it is displayed that the route cannot be found.

image

image

DiogoCunhaMoreira commented 1 month ago

I'm still with the same issue but i found out that the code_verifier is not being sent when doing the token request with the access token. Do you also have the same issue? With postman i have the bad request error not 500 but this is also a issue i think. I try to console log the code_verifier but i get undefined.

itpropro commented 2 weeks ago

@mmillican have you configured the callback url correctly in AWS? I recently tried the generic OIDC provider with AWS Cognito and that worked fine, would you mind sharing your cognito config?

itpropro commented 2 weeks ago

I have the same problem here and would appreciate a solution. The redirect to the IdP and back to the app with the auth code work. But afterwards, it is displayed that the route cannot be found.

image

image

This is just a warning by the Nuxt router, but shouldn't have any impact on the actual functionality. In version 0.12.1 there was a visual fix to get rid of that warning. Would be interesting what the actual request error for the token request on the console is.

itpropro commented 2 weeks ago

If meanwhile you solve this issue please tell us how. I'm also with the same problem and cant figure it out.

Thanks a lot.

Would you mind open a separate issue for the OIDC provider you are trying it with and some details?

DiogoCunhaMoreira commented 2 weeks ago

If meanwhile you solve this issue please tell us how. I'm also with the same problem and cant figure it out. Thanks a lot.

Would you mind open a separate issue for the OIDC provider you are trying it with and some details?

Hey itpropro, thanks for answering. I have opened a issue talking about this and i found a solution, still having problems but at least the 500 dissappeard. You can check it: Title: Token request failed - [nuxt-oidc-auth]: [POST] "https://github.com/login/oauth/access_token": fetch failed

Thanks a lot

mmillican commented 1 week ago

@itpropro sorry for the delay. Here's a screenshot of the relevant config for the callback:

image