问题标签 [passport-google-oauth2]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
99 浏览

node.js - 面临护照js的问题

我是节点 js 的新手,我正在尝试使用谷歌护照做一个授权示例,下面是我的代码:

index.js

最后,我的目标是在不检查数据库的值的情况下成功登录谷歌,因为我只是在学习它。

节点索引.js

然后我打开网址:http://localhost/auth/google

我的程序应该get /final在使用谷歌凭据登录后运行,但出现错误TypeError: done is not a function

我没有得到使用,done()我该如何解决它。

0 投票
1 回答
607 浏览

node.js - passportJS:req.user 返回未定义

我有简单的 passport-facebook 和 google oauth 应用程序,它可以工作,但是我猜它没有正确序列化用户,因为当我登录时req.user它返回未定义。这是我的 facebook oauth 代码

这是护照-谷歌-oauth2

这是路线配置

那么这段代码有什么问题呢?

0 投票
0 回答
180 浏览

google-oauth - 如何区分 Google OAuth 中的实际图片和默认自动生成的图片?

我正在使用 Passport Google 策略 ( OAuth 2.0 ) 从 Google 检索用户数据。这很好用,除非登录用户没有明确设置的个人资料图片。在这种情况下,Google 会返回带有用户名字首字母的默认图片:

在此处输入图像描述

我希望能够判断 API 返回的图像是真实图像还是类似的图像。我该如何做到这一点?这里有一个类似的问题,但答案已经过时,因为谷歌似乎不再提供isDefault标志。对于默认剪影,它也没有一致的 URI,因为不同用户的自动生成图像根据他们的首字母缩写而有所不同。Google OAuth 2.0 是否提供任何替代标志来告诉我图像是否是自动生成的?

0 投票
1 回答
617 浏览

node.js - 向后端 API 响应代理请求以发起 Passport、Google OAuth2 请求

SO社区,

我正在将 Passport 的 Google-OAuth2 策略与 React 前端一起使用。目前,我可以通过 Postman 访问后端 API 调用前面的 Google 登录页面。但是,如果我使用 React 从前端进行调用,React 会将请求视为未知路径并抛出我们的本地 404 页面。

这是我的代码,目前(我已经尝试了几种不同的方法来解决这个问题):

反应组件

我有两个不同的按钮用于测试目的:

  1. <a>按钮”将重定向到我们的 React 404 页面。
  2. 调用该handleGoogleLogin函数的按钮将挂起。Google DevTools 中的“网络”选项卡显示来自 Google 的“待处理”消息。

API 路由

Passport.js

如果我可以提供任何其他信息,请告诉我。

非常感谢!

0 投票
0 回答
29 浏览

reactjs - 如何使用 passport-google-oauth20 使按钮触发 google oauth 流程?

我想在我的 react 应用程序中实现 passport-google-oauth20。我不得不提一下,服务器端一切正常,oauth 流程让我注册并在数据库中创建一个新用户。但在反应中它只显示一个空白页面,地址栏显示这个网址,http://localhost:3000/api/auth/google

按钮:

谷歌.js

谷歌oauth路由

包.json

我想让该按钮正确触发oauth流程。

0 投票
2 回答
1853 浏览

node.js - 内部 OAuth 错误:无法获取用户配置文件 NodeJs+passport-google-oAuth2

我正在学习使用 passport-google-oauth20 进行身份验证。当我尝试使用 Google+ 注册用户时,在未能提交请求后我不断收到此错误消息(InternalOAuthError:无法获取用户个人资料)。

我试过这个解决方案:

  1. 我启用了 Google+ API 并等待。

2.不推荐使用的范围

0 投票
1 回答
615 浏览

node.js - Passport.js - Exchange authorization code received from the client for the access token

Google OAuth 2.0 recommends the following oauth flow:

a hybrid server-side flow where a user authorizes your app on the client side using the JavaScript API client and you send a special one-time authorization code to your server. Your server exchanges this one-time-use code to acquire its own access and refresh tokens from Google for the server to be able to make its own API calls, which can be done while the user is offline.

I am trying to do exactly this but using passport.js instead. In a normal (entirely server-side) workflow, Passport expects one-time authorization code from Google in a query parameter at the redirect link (for example: /auth/google/redirect). Hence, I would expect the same redirect endpoint to work if I call it from my client (with the authorization code), instead of Google redirecting it to.

However, when I try to do that, I get the following error from Passport:

Is it incorrect to expect the code sent from my client-side to work this way? What am I doing wrong?

0 投票
1 回答
180 浏览

passport.js - 无法读取未定义的“加密”属性

我正在尝试使用 Passportjs 和 NestJS(Fastify 作为底层 HTTP 框架)设置 google oauth2。我无法初始化谷歌身份验证屏幕,每次尝试时都会出现错误。我尝试了几种不同的方法来做到这一点,但是 AuthGuard 似乎存在问题,并且每次在这一步代码都会中断。我在这里共享一个控制器片段,它正在处理用于初始化身份验证屏幕的路由。

这是控制器:

谷歌战略:

该模块如下所示:

依赖项

0 投票
2 回答
1358 浏览

node.js - 当只有 1 个 google 帐户登录时,Passport Google Oauth2 不提示选择帐户

我正在尝试在我的 node + nestjs api 中对用户进行身份验证,并希望提示用户选择一个帐户。

如果您只有 1 个帐户登录,则提示不会显示,即使您使用 2 个帐户登录并收到提示,重定向中的 URL 参数中仍然有 &prompt=none。

事实上,我可以确认提示选项没有任何区别。

我的代码简化如下:

我怎么可能进一步调试它以查看引擎盖下为什么/发生了什么?

实际端点:

我无法使用任何警卫或 UseGuards 装饰器传递选项对象。

我还尝试将一个额外的对象参数传递给超级调用,但这也不起作用。

0 投票
2 回答
612 浏览

node.js - 在 Heroku 上实时部署时,passport google oauth2 会导致“内部服务器错误”

我通过 mongoose 连接到 mongoDB,在 localhost 上使用我的应用程序时没有错误,但是当我将它部署到 Heroku 上时,出现内部服务器错误。

这是我的js代码:

这些是我的html代码:

Heroku 日志在他们的错误日志中显示了这一点:

当 Web 应用程序返回“内部服务器错误”页面时。似乎他们在说我的数据库有重复,但我已经清除了我的数据库并且那里没有任何内容了。

请帮助我,我对编程很陌生,所以我仍在学习如何阅读错误代码并理解它们,以便我自己调试。

我已经看到了类似的问题并尝试了提供的解决方案,但它们都不适用于我的情况,这就是我决定提出这个问题的原因。