middleware icon indicating copy to clipboard operation
middleware copied to clipboard

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

Open sabarivasanweb opened this issue 1 year ago • 3 comments

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?

sabarivasanweb avatar Apr 21 '24 12:04 sabarivasanweb

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).

JoaquimLey avatar May 13 '24 23:05 JoaquimLey

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?

sabarivasanweb avatar May 14 '24 03:05 sabarivasanweb

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

Search for "Google oAuth flow"

JoaquimLey avatar May 14 '24 14:05 JoaquimLey