ALB complains about cognito



我正在尝试将应用程序负载均衡器连接到AWS Cognito,除了当我试图保存更改时,我得到了错误"用户池客户端必须有客户端机密",我在谷歌上搜索了它,但没有发现任何有用的东西。

我能够成功地测试Cognito Authentication UI(我想…(,所以我不明白为什么AWS会抱怨用户池客户端。

所以问题是,以前有人遇到过这个问题吗?如果遇到了,你是如何解决的??

编辑:

基本上,我所做的是,一方面我将Cognito配置为仅使用Google OAuth(我删除了亚马逊默认的一个(,另一方面我创建了一个具有多个规则的应用程序负载均衡器,每个规则指向不同的目标组,每个目标组都是运行在Kubernetes上的Docker应用程序。(又名EKS(。所有这些应用程序都有不同类型的身份验证,或者根本没有。因此,我们的想法是在ALB中添加一条规则,以使用Cognito对用户进行身份验证。问题是,在添加了所有必需的参数之后,就在我即将保存更改的时候,所有这些新的更改。我收到一个错误"用户池客户端必须有客户端机密",我在谷歌上搜索了这句话,除了在其他地方发布的帖子外,我什么也没得到。

谢谢你抽出时间!

您在Cognito中创建的应用程序客户端需要应用程序客户端机密。您不能将应用程序客户端机密添加到现有应用程序客户端,但您可以简单地创建一个新的应用程序客户端并勾选"生成机密"框(默认情况下为勾选框(。

这是Cognito和ALB集成实现的Oauth标准的附加安全级别。通过Cognito验证后返回给ALB的"授权码"将由ALB交换给Cognito以换取代币。这种交换需要秘密,由于ALB是唯一知道秘密的应用程序,因此更安全。

为了使AWS Cognito正常工作,您需要一些基本配置。请参阅Amplify的代码摘录(Cognito的AWS开发库(。

import Amplify, { Auth } from 'aws-amplify';
Amplify.configure({
Auth: {
// REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
// REQUIRED - Amazon Cognito Region
region: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito Federated Identity Pool Region 
// Required only if it's different from Amazon Cognito Region
identityPoolRegion: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'XX-XXXX-X_abcd1234',
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
// OPTIONAL - Enforce user authentication prior to accessing AWS resources or not
mandatorySignIn: false,
// OPTIONAL - Configuration for cookie storage
// Note: if the secure flag is set to true, then the cookie transmission requires a secure protocol
cookieStorage: {
// REQUIRED - Cookie domain (only required if cookieStorage is provided)
domain: '.yourdomain.com',
// OPTIONAL - Cookie path
path: '/',
// OPTIONAL - Cookie expiration in days
expires: 365,
// OPTIONAL - Cookie secure flag
// Either true or false, indicating if the cookie transmission requires a secure protocol (https).
secure: true
},
// OPTIONAL - customized storage object
storage: new MyStorage(),
// OPTIONAL - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
authenticationFlowType: 'USER_PASSWORD_AUTH'
}
});
// You can get the current config object
const currentConfig = Auth.configure();

最新更新