How to use passport-google-oauth20 with a SPA react application?

泄露秘密 提交于 2021-02-10 04:48:28

问题


How do I trigger the Google Sign In authorization window to popup?

I'm using JaredHanons' "passport-google-oauth20" library to help with authentication on an application in combination with JSON WebTokens.

My frontend is a single page application with react. I currently have a node.js/express.js api backend and, right now, a separate frontend dev server with react. Frontend wise I have a login button calling:

axios.get("http://localhost:3000/oauth/google/getToken/")

Which is hitting:

`app.get(
  "/oauth/google/getToken",
  passport.authenticate("google", {
    scope: ["profile"]
  })
);`

After it hits the api end point is sends a response with a data value with the RAW Google HTML!
{ data: "<!DOCTYPE html..."; status: 200; }

If type api endpoint in the browser url bar localhost:8080/oauth/google/getToken it loads the raw GoogleSignIn window like I want it to. Is there anyway to redirect to this page on the frontend instead of getting raw html?

来源:https://stackoverflow.com/questions/54272944/how-to-use-passport-google-oauth20-with-a-spa-react-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!