简体   繁体   English

如何在没有前端的情况下使用 Postman 在 Node.js Express 后端服务器上测试 Passport JS Google OAuth

[英]How to test Passport JS Google OAuth on Node.js Express backend server without a frontend using Postman

I am trying to implement google Oauth into a backend application I am creating for a food delivery app I am building.我正在尝试将 google Oauth 实现到我正在为我正在构建的送餐应用程序创建的后端应用程序中。 I have already implemented cookies and auth with passportJS which is working great and was super easy to test with Postman.我已经实施了 cookies 并使用 passportJS 进行了身份验证,它运行良好并且非常容易使用 Postman 进行测试。

I am now trying to implement google Oauth but have no idea how I am supposed to specify the path the request comes from or how to get postman to send a response to my server to confirm login success or failure nor how to get it to redirect me to a google window where I can login my test user.我现在正在尝试实施 google Oauth 但不知道我应该如何指定请求来自的路径或如何让 postman 向我的服务器发送响应以确认登录成功或失败,也不知道如何让它重定向我到谷歌 window 我可以登录我的测试用户。 I really don't want to have to build out the entire login section of my frontend just to test google OAuth and there seems to be no tutorial on how to test this functionality of your Node API with Postman.我真的不想为了测试 google OAuth 而构建我前端的整个登录部分,而且似乎没有关于如何使用 Postman 测试节点 API 的此功能的教程。

The frontend I will eventually build will be in ReactJS.我最终将构建的前端位于 ReactJS。

Any explanation or direction to a tutorial that explains this would be massively appreciated.对解释这一点的教程的任何解释或指导将不胜感激。

To use OAuth 2.0:要使用 OAuth 2.0:

  1. In the Authorization tab for a request, select OAuth 2.0 from the Type dropdown list.在请求的授权选项卡中,类型下拉列表中的 select OAuth 2.0。 Specify if you want pass the auth details in the request URL or headers.指定是否要在请求 URL 或标头中传递身份验证详细信息。

  2. By default Postman will append the access token to Bearer in the Authorization header for your request, but if your server implementation requires a different prefix, you can specify it in the Header Prefix field.默认情况下,Postman 将在授权 header 中为您的请求提供 append 访问令牌,但如果您的服务器实现需要不同的前缀,您可以在 Header 前缀字段中指定它。

  3. To request an access token, fill out the fields in the Configure New Token section, and select Get New Access Token.要请求访问令牌,请填写配置新令牌部分中的字段,然后输入 select 获取新访问令牌。 You can save both the token and the details to generate a token with your request or collection.您可以保存令牌和详细信息以生成带有您的请求或集合的令牌。

  4. Once you have a token value generated and added, it will appear in the request Headers.生成并添加令牌值后,它将出现在请求标头中。

  5. Enter the details for your client application, and any auth details from the service provider.输入您的客户端应用程序的详细信息,以及来自服务提供商的任何身份验证详细信息。 This allows you to replicate your application auth flow inside Postman in order to test authenticated requests.这允许您在 Postman 内复制您的应用程序身份验证流程,以测试经过身份验证的请求。

  6. You can share token credentials with your team by selecting the sync token icon Syncing icon next to an available token.您可以通过选择可用令牌旁边的同步令牌图标 Syncing 图标来与您的团队共享令牌凭据。 By default Postman won't sync your token in case you don't want to share it.默认情况下,Postman 不会同步您的令牌,以防您不想共享它。

  7. Postman will prompt you to supply specific details depending on the OAuth 2.0 grant type, which can be Authorization code, Implicit, Password credentials, or Client credentials. Postman 将提示您根据 OAuth 2.0 授权类型提供具体详细信息,可以是授权代码、隐式、密码凭据或客户端凭据。

Note:笔记:

  1. Use https://oauth.pstmn.io/v1/browser-callback for callback url. (once user initiates oauth, postman will open url in new browser window. Once authorizaiton is completed, it will hit this url)使用https://oauth.pstmn.io/v1/browser-callback回调 url。(一旦用户启动 oauth,postman 将在新浏览器 url 中打开 url,一旦完成,作者将点击此链接)
  2. Postman can save autorizaition code from above call back url to get refresh token and access token. Postman可以保存上面回调url获取刷新令牌和访问令牌的自动化代码。 (with this, postman can issue new access tokens for you to use) (有了这个,postman 可以颁发新的访问令牌供您使用)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM