Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

How to get Google provider ID token #2427

Closed
sjbzhc opened this issue Jul 26, 2021 · 0 comments
Closed

How to get Google provider ID token #2427

sjbzhc opened this issue Jul 26, 2021 · 0 comments
Labels
question Ask how to do something or how something works

Comments

@sjbzhc
Copy link

sjbzhc commented Jul 26, 2021

Question 💬

Hi,

I am trying to log in and get an id_token.

My config is as follows:

const providers = [
        Providers.Google({
            clientId: process.env.GOOGLE_ID,
            clientSecret: process.env.GOOGLE_SECRET,
            idToken: true,
        }),
    ]

const pages = { signIn: "/login" };

const callbacks =  {
  async jwt(token, user, account, profile, isNewUser, idToken) {
    console.log('token :>> ', token);
    console.log('idToken :>> ', idToken);
    if (account?.accessToken) {
      token.accessToken = account.accessToken;
    }
    return token;
  }
};

const options = {
  providers,
  callbacks,
  pages
};

const auth = (req, res) => NextAuth(req, res, options);

I already reviewed #393 and if I understand correctly, I should be able to access the idToken in the jwt callback as described in #837.

In the documentation I also read that I can override the options of the provider, so I added idToken: true.

If I don't override tokenId to true, I am able to log in, but I have no access to the idToken.

After overriding idTioken to true, I get following error:

[next-auth][error][oauth_callback_handler_error]
https://next-auth.js.org/errors#oauth_callback_handler_error Error: Missing or invalid provider account
    at callbackHandler (/Users/user/projects/basic-next/node_modules/next-auth/dist/server/lib/callback-handler.js:18:119)
    at Object.callback (/Users/user/projects/basic-next/node_modules/next-auth/dist/server/routes/callback.js:100:48)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)

How to reproduce ☕️

Override tokenId to true in the Google provide options:

    Providers.Google({
      clientId: process.env.GOOGLE_ID,
      clientSecret: process.env.GOOGLE_SECRET,
      idToken: true
    }),

Contributing 🙌🏽

Yes, I am willing to help answer this question in a PR

@sjbzhc sjbzhc added the question Ask how to do something or how something works label Jul 26, 2021
@nextauthjs nextauthjs locked and limited conversation to collaborators Jul 26, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Ask how to do something or how something works
Projects
None yet
Development

No branches or pull requests

2 participants