将 Amazon API 网关与 Amazon Cognito 集成以用于 .Net Framework 桌面应用程序
Integrating Amazon API Gateway with Amazon Cognito for use in a .Net Framework Desktop Application
我们正在尝试设置桌面应用程序,需要通过多因素身份验证登录才能连接到亚马逊的 API 网关。为此,我们使用 Amazon Cognito 进行身份验证,目的是将其与 API 网关集成。设置的 Cognito 和 API 网关部分独立工作。添加安全性会带来问题。
按照此处的文档:https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-integrate-with-cognito.html,我们已将 API 网关配置为使用授权方和令牌,通过 Cognito 成功登录后会收到令牌。在AWS控制台测试authorizer时,收到的token有效,认证通过
尝试从桌面应用程序执行此操作时会出现问题。经过数小时的文档搜索和无休止的谷歌搜索后,我们仍然离它的工作更进一步。
文档说我们必须使用 'Authorization' 键将令牌放入请求的 header 中。我们这样做但只是不断收到 HTTP 401(未授权)。
发送的请求header如下(第一个黑色矩形是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.
有谁知道我们做错了什么吗?
非常感谢
对于将来遇到此问题的任何人。该问题与传递的令牌无关。检查令牌后,我们发现范围不匹配。
我们曾尝试在 Cognito 中使用自定义范围,但由于某些原因,自定义范围在桌面应用程序中并不真正起作用(范围一直默认为 aws.cognito.signin.user.admin)。
总之,长话短说。我们现在使用 lambda 授权方来验证从我们的认知用户池中获取的 ID jwt 令牌。然后我们根据发出请求的用户组分配权限。
我们正在尝试设置桌面应用程序,需要通过多因素身份验证登录才能连接到亚马逊的 API 网关。为此,我们使用 Amazon Cognito 进行身份验证,目的是将其与 API 网关集成。设置的 Cognito 和 API 网关部分独立工作。添加安全性会带来问题。
按照此处的文档:https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-integrate-with-cognito.html,我们已将 API 网关配置为使用授权方和令牌,通过 Cognito 成功登录后会收到令牌。在AWS控制台测试authorizer时,收到的token有效,认证通过
尝试从桌面应用程序执行此操作时会出现问题。经过数小时的文档搜索和无休止的谷歌搜索后,我们仍然离它的工作更进一步。
文档说我们必须使用 'Authorization' 键将令牌放入请求的 header 中。我们这样做但只是不断收到 HTTP 401(未授权)。
发送的请求header如下(第一个黑色矩形是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.
有谁知道我们做错了什么吗?
非常感谢
对于将来遇到此问题的任何人。该问题与传递的令牌无关。检查令牌后,我们发现范围不匹配。
我们曾尝试在 Cognito 中使用自定义范围,但由于某些原因,自定义范围在桌面应用程序中并不真正起作用(范围一直默认为 aws.cognito.signin.user.admin)。
总之,长话短说。我们现在使用 lambda 授权方来验证从我们的认知用户池中获取的 ID jwt 令牌。然后我们根据发出请求的用户组分配权限。