简体   繁体   English

如何将AWS Cognito与自定义NodeJS服务器一起使用?

[英]How do you use AWS Cognito with a custom NodeJS server?

I am building an app using Angular and NodeJS. 我正在使用Angular和NodeJS构建应用程序。

I've heard about AWS Cognito and would like to use it in my app. 我听说过AWS Cognito,并希望在我的应用程序中使用它。 However it is very unclear in the documentation how it is supposed to work. 但是,在文档中尚不清楚它应该如何工作。

There is an example on how to use Cognito with an Angular SPA, but there is no word on how I can use it to authenticate users on my backened NodeJS server. 有一个关于如何在Angular SPA中使用Cognito 的示例 ,但是没有关于如何使用它来对我的备份NodeJS服务器上的用户进行身份验证的消息。

How is NodeJS supposed to know if a user is logged in? NodeJS应该如何知道用户是否已登录? I can think of several possible answers, but none appear in the documentation and there is surprisingly no code sample. 我可以想到几个可能的答案,但是没有答案出现在文档中,而且令人惊讶的是没有代码示例。 So I decided to ask here before investing a lot of time in trial and error. 因此,我决定在投入大量时间进行反复试验之前先在这里询问。

You can use AWS Cognito Userpools in your backend NodeJS server to authenticate users. 您可以在后端NodeJS服务器中使用AWS Cognito Userpools对用户进行身份验证。 The steps are as follows. 步骤如下。

  • Create a Cognito Userpool and setup an App Client. 创建一个Cognito用户池并设置一个App Client。
  • Create a Cognito Userpool ( Optionally Cognito Federated Identities if you want your users to directly allow controlled access to AWS services). 创建一个Cognito用户池(如果希望用户直接允许对AWS服务的受控访问,则可以选择Cognito联合身份)。
  • Configure Cognito Hosted UI ( Built in Signin page and optionally Signup page). 配置Cognito托管UI(“内置登录”页面和(可选)“注册”页面)。
  • For User Signin, redirect the User to this Domain URL for Signin. 对于用户登录,将用户重定向到该域URL进行登录。
  • Setup an App Client with redirect URLs to your App for Oauth2 flow. 使用重定向URL设置到App Client的App Client进行Oauth2流。
  • After user Signin, you will receive an id_token (eg In implicit grant flow) in URL which you can forward to your NodeJS server where you can validate it using NodeJS middleware. 用户登录后,您将在URL中收到一个id_token(例如,在隐式授予流中),您可以将其转发到NodeJS服务器,在其中可以使用NodeJS中间件对其进行验证。
  • You can decide whether to store the id_token in a cookie or in browser storage and implement the storage and validation accordingly for subsequent requests. 您可以决定将id_token存储在cookie还是浏览器存储中,并为后续请求相应地实现存储和验证。

Note: Since the id_token is a standard JavaScript Web Token (JWT) you can find a library to validate it. 注意:由于id_token是标准的JavaScript Web令牌(JWT),因此您可以找到一个库对其进行验证。 Refer AWS documentation Using Tokens with User Pools for more details. 有关更多详细信息,请参阅AWS文档将令牌与用户池一起使用

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

相关问题 我如何使用 Azure AD 像 AWS cognito 来注册/登录用户和 api 身份验证和自定义 UI,因为我可以在 Cognito 中做到这一点? - How can i use Azure AD like AWS cognito to signup/signin users and api authentication with custom UI as i can do it in the Cognito? 如何将自定义 AWS 开发工具包与 nodejs 结合使用? - How do I use a custom AWS SDK with nodejs? AWS - 使用nodejs的Cognito Identity - 如何处理令牌 - AWS - Cognito Identity with nodejs - What to do with tokens 如何将 AWS Cognito SSO 与托管在 Azure 上的后端服务器一起使用? - How to use AWS Cognito SSO with Backend Server Hosted on Azure? 如何在没有Amazon Cognito的情况下使用AWS S3? - How do I use AWS S3 without Amazon Cognito? 如何在NodeJS上验证AWS Cognito访问令牌 - How to verify AWS Cognito Access Token on NodeJS 您能否以编程方式创建 AWS Cognito 应用程序客户端? (节点) - Can you create AWS Cognito App Client Programmatically? (nodejs) 如何使用AWS Cognito SDK使用NodeJS从REST服务验证用户? - How to use AWS Cognito SDK to authenticate user from REST Service using NodeJS? 如何使用 AWS Cognito 与 Nodejs UI 应用程序和 Oauth 2.0 流使用护照 js? - How to use AWS Cognito with Nodejs UI app and Oauth 2.0 flow using passport js? 如何强制 AWS Cognito:signUp() 同步执行(nodejs) - How to force AWS Cognito: signUp() to execute synchronously (nodejs)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM