fastify-oauth2 icon indicating copy to clipboard operation
fastify-oauth2 copied to clipboard

discovery looped bugs report with auth config

Open RodrigoDornelles opened this issue 1 year ago • 1 comments
trafficstars

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.25.2

Plugin version

7.8.0

Node.js version

20.11.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

5.15.0-91-generic

Description

I'm not able to configure it according to the README.md example

fastify.register(oauthPlugin, {
 name: 'customOAuth2',
 scope: ['profile', 'email'],
 credentials: {
   client: {
    id: '<CLIENT_ID>',
     secret: '<CLIENT_SECRET>',
  },
 },
 startRedirectPath: '/login',
 callbackUri: 'http://localhost:3000/callback',
 discovery: { issuer: 'https://identity.mycustomdomain.com' }
});

Steps to Reproduce

Bug 1

config

app.register(fastifyOAuth2, {
      name: 'keycloakOAuth2',
      scope: process.env.KEYCLOAK_OPENID_SCOPES?.split(','),
      credentials: {
        client: {
          id: `${process.env.KEYCLOAK_OPENID_CLIENT}`,
          secret: `${process.env.KEYCLOAK_OPENID_SECRET}`,
        },
        auth: {
          authorizeHost: `${process.env.KEYCLOAK_OPENID_URL}`,
          authorizePath: `${process.env.KEYCLOAK_OPENID_AUTH_PATH}`,
          tokenHost: `${process.env.KEYCLOAK_OPENID_URL}`,
          tokenPath: `${process.env.KEYCLOAK_OPENID_TOKEN_PATH}`,
        },
      },
      discovery: {
        issuer: `${process.env.KEYCLOAK_OPENID_URL}/${process.env.KEYCLOAK_ISSUER}`
      },
      startRedirectPath: '/login/keycloak',
      callbackUri: `${process.env.URL}/login/keycloak/callback`,
});

error

[ERROR] 12:22:44 Error: when options.discovery.issuer is configured, credentials.auth should not be used

Bug 2

config

app.register(fastifyOAuth2, {
      name: 'keycloakOAuth2',
      scope: process.env.KEYCLOAK_OPENID_SCOPES?.split(','),
      credentials: {
        client: {
          id: `${process.env.KEYCLOAK_OPENID_CLIENT}`,
          secret: `${process.env.KEYCLOAK_OPENID_SECRET}`,
        },
      },
      discovery: {
        issuer: `${process.env.KEYCLOAK_OPENID_URL}/${process.env.KEYCLOAK_ISSUER}`
      },
      startRedirectPath: '/login/keycloak',
      callbackUri: `${process.env.URL}/login/keycloak/callback`,
});

error

[ERROR] 12:19:17 ValidationError: Invalid options provided to simple-oauth2 "auth.tokenHost" is required

Expected Behavior

No response

RodrigoDornelles avatar Feb 08 '24 12:02 RodrigoDornelles