Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using userinfo with googleoauth errors "userinfo can not be used without discovery" #260

Open
2 tasks done
krishna-404 opened this issue May 25, 2024 · 2 comments
Open
2 tasks done

Comments

@krishna-404
Copy link

krishna-404 commented May 25, 2024

Prerequisites

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

Fastify version

4.27.0

Plugin version

7.8.1

Node.js version

20.10.0

Operating system

macOS

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

12.3.1

Description

Usine userinfo with googleOauth2 gives a throws an error

"userinfo can not be used without discovery"

Google gives a id_token, which it suggests to validate locally & get user details from the same. Documentation from google is below

  1. https://developers.google.com/identity/openid-connect/openid-connect#validatinganidtoken
  2. https://developers.google.com/identity/openid-connect/openid-connect#discovery

Link to code that reproduces the bug

No response

Expected Behavior

googleOauth2.userinfo(token) should return the user object by locally parsing the jwt.

@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@bayramkzk
Copy link

  fastify.register(oauthPlugin, {
    name: 'googleOAuth2',
    scope: ['openid', 'profile', 'email'],
    credentials: {
      client: {
        id: process.env.GOOGLE_OAUTH2_CLIENT_ID!,
        secret: process.env.GOOGLE_OAUTH2_CLIENT_SECRET!,
      },
      // auth: oauthPlugin.GOOGLE_CONFIGURATION,
    },
    startRedirectPath: '/login/google',
    callbackUri: callbackUri('google'),
    discovery: {
      issuer: 'https://accounts.google.com',
    },
  })

It works without any errors if opts.credentials.auth is not provided and opts.discovery is set to 'https://accounts.google.com' like above. I am not sure if this is intended behavior or a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants