简体   繁体   English

如何在没有应用程序客户端密钥的情况下使用 Cognito OAuth 2.0 对 API 网关请求进行身份验证?

[英]How can I use Cognito OAuth 2.0 to authenticate a API Gateway request without having an app client secret?

I'm using aws sdk to manage logins and signups on my app and the sdk requires my app client to have no secret key.我正在使用 aws sdk 来管理我的应用程序的登录和注册,并且 sdk 要求我的应用程序客户端没有密钥。 This is a problem since I intend to use Cognito to authenticate the API gateway.这是一个问题,因为我打算使用 Cognito 来验证 API 网关。 I tried to enable OAuth 2.0 client credentials flow on app client settings, select a scope and give it to the API method, but when I try to save the app client settings I get:我尝试在应用程序客户端设置上启用 OAuth 2.0 客户端凭据流,选择一个范围并将其提供给 API 方法,但是当我尝试保存应用程序客户端设置时,我得到:

"We were unable to update your App Configuration: client_credentials flow can not be selected if client does not have a client secret. (Service: AWSCognitoIdentityProviderService; Status Code: 400; Error Code: InvalidOAuthFlowException" “我们无法更新您的应用程序配置:如果客户端没有客户端密钥,则无法选择 client_credentials 流。(服务:AWSCognitoIdentityProviderService;状态代码:400;错误代码:InvalidOAuthFlowException”

Is there a better way to configure API Gateway with Cognito?有没有更好的方法来使用 Cognito 配置 API 网关? Am I doing something wrong?难道我做错了什么?

You need to create a new app client for your API with a secret.您需要使用密钥为您的 API 创建一个新的应用程序客户端。

front end client - app client with out secret Backend client / api - app client with secret前端客户端 - 没有秘密的应用程序客户端 后端客户端 / api - 有秘密的应用程序客户端

Client credentials is a usually a method for service-service authentication.客户端凭据通常是一种用于服务-服务身份验证的方法。 You have to store the secret securely.therefore insecure to use in an unsafe front end app such as an html website.您必须安全地存储秘密。因此在不安全的前端应用程序(例如 html 网站)中使用是不安全的。

Hope this helps.希望这可以帮助。

To add to Arun's answer, the API should not need a Cognito OAuth client entry and just needs to validate received Cognito access tokens.要添加到 Arun 的答案中,API 不需要 Cognito OAuth 客户端条目,只需要验证收到的 Cognito 访问令牌。

Typically this is done by downloading JWKS keys from Cognito - and API Gateway has a setting that automatically does this.通常这是通过从 Cognito 下载 JWKS 密钥来完成的 - API Gateway 有一个自动执行此操作的设置。

I can provide further details if you run into problems identifying the user after token validation.如果您在令牌验证后遇到识别用户的问题,我可以提供更多详细信息。

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

相关问题 如何在不使用 AWS API 网关的情况下使用 Cognito 对对我的 API 的请求进行身份验证 - How can I use Cognito to authenticate requests to my API without using AWS API Gateway 如何使用 cognito 验证我的 api 网关? - How can I authenticate my api gateway with cognito? 如何使用AWS Cognito对API网关进行身份验证 - How to use AWS Cognito to authenticate API Gateway 使用 Cognito 向 AWS API Gateway 验证应用程序 - Authenticate app to AWS API Gateway with Cognito 没有API网关的情况下如何认证AWS Lambda? - How can I authenticate AWS Lambda without an API Gateway? 如何使用AWS Cognito响应对API请求进行身份验证 - How do I use AWS cognito response to authenticate API requests 如何使用 API Gateway Cognito Authorizer 对访客/未经身份验证的用户进行身份验证? - How to authenticate Guest/Unauthenticated users with API Gateway Cognito Authorizer? 我可以使用 Aws Cognito 对 Twitter 进行身份验证吗? - Can I use Aws Cognito authenticate with Twitter? 如何使用 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? 在API网关中传递OAUTH2.0访问令牌获取请求 - Passing OAUTH2.0 access token in API gateway get request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM