I have a MERN application and I want to obtain the following behaviour in my app:
- A user logs in with with google using the
GoogleLogincomponent in the@react-oauth/googlepackage - After the user logs in and gives permission to my app to access some Google API (e.g. Google Calendar), I want to send the JWT generated from the login process to the Node.js backend
- I want to "extract" access and refresh tokens from this JWT (decoding it in some way?)
- I want to store the tokens in a persistent way so that I can access the user's calendar whenever I want
I managed to get this done with the GoogleLogin from react-google-login package, which gives you a code that can be exchanged for tokens in the backend. But this library has been recently deprecated (when I try to log in with this button I get this error: idpiframe_initialization_failed). I don't know anymore how to use this library.
This is the code that I use to login:
<GoogleOAuthProvider clientId={"MY_CLIENT_ID"}>
<GoogleLogin
onSuccess={this.onSuccess}
onFailure={this.onFailure}
/>
</GoogleOAuthProvider>;
And this is the object I get when the log in is successful:
{
clientId: "MY_CLIENT_ID"
credential: "JWT_string"
select_by: "btn"
}
I'm not sure this is the right approach to use in order to get access and refresh tokens to use in the backend, or if there's a better way to do so with the new Google Identity Services SDK.