I am trying to make a simple ReactJS webapp where I can fetch for example the authenticated user's steps.
I'm using React OAuth2 | Google for the authentication and I can successfully get the user's JWT.
<GoogleLogin
onSuccess={credentialResponse => {
console.log(credentialResponse);
setUser(credentialResponse);
}}
onError={() => {
console.log('Login Failed');
}}
/>
)}
</GoogleOAuthProvider>
But now I'am at loss. I'm simply trying to call an endpoint with the JWT but I only get 401. I understand I should use an access token instead but since Google has moved to the new Google Identity Services, I have no idea how to get an access token from JWT, or use the JWT to authenticate and call these endpoints.
axios
.get(GOOGLE_FIT_ENDPOINT, {
headers: {
Authorization: `Bearer ${user.credential}`,
Accept: 'application/json'
}
})
.then((res) => {
setProfile(res.data);
})
.catch((err) => console.log(err));
Since it's new, I could not find any documentation or tutorial about it.
All I could find was how to get the JWT token, or how to call a Google API endpoint with access or refresh token. But there must be a step in the middle I'm missing.
FIY, I also set up a Express JS server as a backend.
Could anyone point me out to the right direction please?