Search code examples
node.jsexpressauthenticationgoogle-apigoogle-oauth

How can I verify login using google api, oauth?


I want to use google oauth api to log in to the site which I create.

I use react and node and I'm done with getting current access_token issued but I'm not sure how to know if the user is logged in.

  • Should I check the user's access_token every time the user calls the api of my site?

  • If that's correct, should the access_token be held by the client?

  • Isn't that a security issue?

I did a lot of searching but I don't know how to manage access_token and how to check if user is logged in.

This is the article I referenced


Solution

  • Should I check the user's access_token every time the user calls the api of my site?

    Yes. The only ones you will not check will the public ones.

    If that's correct, should the access_token be held by the client?

    Yes, it can be stored in cookies, local storage... Is is debatable which is the best solutions, you can articles such as this one

    Isn't that a security issue?

    No. Anybody can check the content of a JWT token (just paste the content here). But the neat thing is that it can't be modified or manipulated. Of course, it is advisable to keep it as safe as a password, so don't share it around :)