【问题标题】:Integrating Amazon API Gateway with Amazon Cognito for use in a .Net Framework Desktop Application将 Amazon API Gateway 与 Amazon Cognito 集成以在 .Net Framework 桌面应用程序中使用
【发布时间】:2021-02-12 14:30:32
【问题描述】:

我们正在尝试设置一个桌面应用程序,该应用程序需要多因素身份验证登录才能连接到亚马逊的 API 网关。为此,我们使用 Amazon Cognito 进行身份验证,旨在将其与 API 网关集成。设置的 Cognito 和 API 网关部分都独立工作。问题在于添加安全性。

按照此处的文档:https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-integrate-with-cognito.html,我们已将 API 网关配置为使用授权方和令牌,通过 Cognito 成功登录时会收到该令牌。在AWS控制台测试授权方时,收到的token有效,认证通过。

尝试从桌面应用程序执行此操作时会出现此问题。经过数小时的文档和无休止的谷歌搜索后,我们仍然离让它工作更近了一步。

文档说我们必须使用“授权”键将令牌放在请求的标头中。我们这样做,但只是不断收到 HTTP 401(未经授权)。

正在发送的请求头如下(第一个黑色矩形是api端点,第二个是我们传入的token):

使用 postman 等 3rd 方应用时会看到相同的结果。

根据以下文档:https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-troubleshooting-jwt.html,我们尝试了 curl 命令:curl -v -H "Authorization: <token>" <endpoint>

但只是不断收到响应:

*   Trying <ip>...
* TCP_NODELAY set
* Connected to <endpoint> port 443 (#0)
* schannel: SSL/TLS connection with <endpoint> port 443 (step 1/3)
* schannel: checking server certificate revocation
* schannel: sending initial handshake data: sending 217 bytes...
* schannel: sent initial handshake data: sent 217 bytes
* schannel: SSL/TLS connection with <endpoint> port 443 (step 2/3)
* schannel: failed to receive handshake, need more data
* schannel: SSL/TLS connection with <endpoint> port 443 (step 2/3)
* schannel: encrypted data got 4096
* schannel: encrypted data buffer: offset 4096 length 4096
* schannel: encrypted data length: 4030
* schannel: encrypted data buffer: offset 4030 length 4096
* schannel: received incomplete message, need more data
* schannel: SSL/TLS connection with <endpoint> port 443 (step 2/3)
* schannel: encrypted data got 1024
* schannel: encrypted data buffer: offset 5054 length 5054
* schannel: encrypted data length: 180
* schannel: encrypted data buffer: offset 180 length 5054
* schannel: received incomplete message, need more data
* schannel: SSL/TLS connection with <endpoint> port 443 (step 2/3)
* schannel: encrypted data got 167
* schannel: encrypted data buffer: offset 347 length 5054
* schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.
* Closing connection 0
* schannel: shutting down SSL/TLS connection with <endpoint> port 443
* schannel: clear security context handle
curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.

有人知道我们做错了什么吗?

在此先感谢

【问题讨论】:

    标签: .net amazon-web-services api amazon-cognito gateway


    【解决方案1】:

    对于将来遇到此问题的任何人。该问题与传递的令牌无关。检查令牌后,我们发现范围不匹配。

    我们曾尝试在 Cognito 中使用自定义范围,但由于某些原因,自定义范围在桌面应用程序中实际上并不适用(范围一直默认为 aws.cognito.signin.user.admin)。

    总之,长话短说。我们现在使用 lambda 授权器来验证从我们的 cognito 用户池中获取的 ID jwt 令牌。然后,我们根据发出请求的用户组分配权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-26
      • 2017-06-21
      • 2020-07-28
      • 1970-01-01
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多