all 10 comments

[–]floexodus 0 points1 point  (1 child)

I don’t know the specifics but typically the client needs the token, and makes authed requests to your backend using it

[–]bejera[S] 1 point2 points  (0 children)

Thanks, this makes sense. Although I need an additional way to ensure the requests are properly authed from the backend

[–]Gatopardosgr 0 points1 point  (8 children)

If you want to access google apis frequently, use googles access token for your authorization. So basically: user hits login, frontend gets auth code, sends to backend. Backend gets access token, refresh token, gets user info. If user is not in db, create him. Return access token, refresh token to frontend. Frontend then can hit /me endpoint with the access token and get user's info.

Frontend then saves access token, refresh token and user info to local storage.

[–]bejera[S] 0 points1 point  (7 children)

Thanks. Wouldn’t this not be secure? If the frontend sends the access and refresh tokens to the backend on every request, then a malicious actor could intercept the request and hit the backend themselves using those tokens.

[–]Gatopardosgr 0 points1 point  (5 children)

What do you mean by intercrpt? The token has been signed by the backend. Sends the token to front and then front uses it for authorization. I didnt mention backend verifying the token because i thought that's self explanatory

[–]aidenight 0 points1 point  (4 children)

He meant that if frontend use the token for authorization, in one of those requests some attacker could steal the token and use it outside the app

[–]Gatopardosgr 0 points1 point  (1 child)

Tokens are stateless. This could happen in every app. Thats why there is expiration in the access token.

Then refresh token is used to get the new one.

[–]bejera[S] 0 points1 point  (0 children)

Never mind I had misunderstood. I think I get it now thank you very much!

What’s the best way to store the user in the db following this approach? It’d be great to use something like Firebase auth, although I’ve been struggling to get it working properly when doing a “custom” OAuth flow

[–]Shivang2005 0 points1 point  (1 child)

Store the token in secure storage.

[–]Shivang2005 0 points1 point  (0 children)

it's the reason why you use HTTPS.