AWS Cognito的Amplify SDK在使用SRP协议时,确实会将新密码以明文方式发送到服务器。这是因为SRP协议涉及到客户端和服务器端进行加密计算,并且需要对密码进行哈希计算来生成客户端的临时密码。因此,即使在SRP协议的情况下,密码仍然需要在客户端和服务器端之间传递。
但AWS Cognito引入了一种名为KDF(Key Derivation Function)的机制,它可以确保密码在传输过程中得到保护。因此,要确保新密码在传输过程中得到保护,请使用以下代码:
import Amplify from 'aws-amplify';
import { AWSIoTProvider } from '@aws-amplify/pubsub/lib/Providers';
Amplify.configure({
Auth: {
userPoolId: 'YOUR_USER_POOL_ID',
userPoolWebClientId: 'YOUR_USER_POOL_CLIENT_ID',
mandatorySignId: true,
authenticationFlowType: 'USER_PASSWORD_AUTH',
passwordProtectionSettings: {
passwordPolicyMinLength: 8,
passwordPolicyCharacters: [
'REQUIRE_DIGIT',
'REQUIRE_LOWER_CASE',
'REQUIRE_UPPER_CASE',
'REQUIRE_SYMBOL',
],
},
refreshTokens: true,
identityPoolId: 'cognito-identity-pool-id',
region: 'REGION',
userPoolMfaType: 'OFF',
oauth: {
domain: 'domain.auth.us-east-1.amazoncognito.com',
scope: ['phone', 'email', 'profile', 'openid', 'aws.cognito.signin.user.admin'],
callbackRedirectSignOut: 'http://localhost:3000',
redirectSignIn: 'http://localhost:3000',
redirectSignOut: 'http://localhost:3000',
responseType: 'code',
userPoolId: 'us-east-1_USER-POOLID',
clientId: '265xxxxxx'
},