In @react-oauth/google when i use googleonetap it returns me the user token in…
- User
In @react-oauth/google when i use googleonetap it returns me the user token in credential but when i use googlelogin it returns me access_token instead of credential. Why and how can i solve it?
- Assistant
The reason why you are receiving different tokens with
GoogleOneTapandGoogleLoginis due to the differences in the OAuth2 flows used by each method.GoogleOneTapuses the "One Tap" flow, which is a simplified authentication flow that only requires a user to click a button to authenticate. This flow returns acredentialobject, which contains anidTokenand anaccessToken. TheidTokenis a JSON Web Token (JWT) that contains information about the user and the authentication process, while theaccessTokencan be used to access Google APIs on behalf of the user.On the other hand,
GoogleLoginuses the standard OAuth2 flow, which involves redirecting the user to the Google sign-in page to enter their credentials. This flow returns anaccess_tokenthat can be used to access Google APIs on behalf of the user.If you need to access the user's
idTokenusingGoogleLogin, you can include the parameter in the options. This will return an in addition to the . For example: - User
Ok but when i try to verify access_token via https://www.googleapis.com/oauth2/v2/userinfo i get cors policy error
- Assistant
If you are getting a CORS policy error when trying to verify the
access_tokenusing thehttps://www.googleapis.com/oauth2/v2/userinfoendpoint, it means that the server hosting your website is blocking cross-origin requests to that endpoint.To resolve this issue, you can either:
- Make the request to the endpoint from your server-side code, rather than from the client-side code running in the user's browser. This way, the request will not be subject to the same CORS restrictions as client-side code.