honojs / middleware

monorepo for Hono third-party middleware/helpers/wrappers
https://hono.dev
470 stars 168 forks source link

The access token received from google oauth-providers/google is not valid JWT #468

Open sabarivasanweb opened 7 months ago

sabarivasanweb commented 7 months ago

I am pretty new to hono and oauth. I am using this straight forward googleauth implementation

import { Hono } from 'hono'
import { googleAuth } from '@hono/oauth-providers/google';

const app = new Hono();

app.get('/auth/google/sign-in',
  googleAuth({
    client_id: Bun.env.GOOGLE_ID,
    client_secret: Bun.env.GOOGLE_SECRET,
    scope: ['openid', 'email', 'profile'],
  }),
  (c) => {
    const token = c.get('token')
    const grantedScopes = c.get('granted-scopes')
    const user = c.get('user-google')

    return c.json({
      token,
      grantedScopes,
      user,
    })
  })

export default app

This is the sample token i am receiving

ya29.a0Ad52N39jfonKlkt81bjY8RntmIr-O9oD2uPhOkyC4zRniCgY49qbDkW3cZ-MEz6ZdraJQC1LHFtgQAka6fGRxyoV0YSCXZzSJmKWsR_qrjW3DlMTVTX9DsLYYLXO_ghRIMi2rJLmjU7Yqc3SMhXC84VBAPyO1vxRywaCgYKAXUSARASFQHGX2MioTv67Z0opiAWcEKQ89BINg0169

I am wondering if its a JWT or not. It supposed to be an access token but i cant verify it with my secret. I am receiving the user data correctly. Is it a valid token? if not how can i get valid JWT token?

JoaquimLey commented 6 months ago

That token is used to talk with Google APIs and not your own server, it is not your JWT secret (you never pass it or should).

Depending on your use case, store the incoming data from Google (such as the user profile) on your database and then create a JWT using your secret with the desired payload/data you want to pass down to the client (eg: a Frontend application).

sabarivasanweb commented 6 months ago

That token is used to talk with Google APIs and not your own server, it is not your JWT secret (you never pass it or should).

Depending on your use case, store the incoming data from Google (such as the user profile) on your database and then create a JWT using your secret with the desired payload/data you want to pass down to the client (eg: a Frontend application).

Is that it. Is it possible to get more details or a related documentation about the token received?

JoaquimLey commented 6 months ago

Yes, if you do your own research you'll find all the details you need.

Search for "Google oAuth flow"