AWS Amplify 'currentUserCredentials()' returns 意外的验证值,错误?
AWS Amplify 'currentUserCredentials()' returns unexpected authenticated value, bug?
在 Auth.signIn() 之后调用 Auth.currentUserCredentials() 时,我获得了有效的凭据,但对于未经身份验证的用户,为什么?
代码:
async signIn({ dispatch, state }, { email, password }) {
try {
const user = await Auth.signIn(email, password);
console.log("User state after login")
const userCredentialsAfterLogin = await Auth.currentUserCredentials();
console.log(userCredentialsAfterLogin)
} catch (error) {
console.log("error")
console.log(error)
return
}
await dispatch('fetchUser')
},
预期行为:
使用有效用户登录后,Auth.currentUserCredentials() 应该 return 一组经过身份验证的凭据。
实际行为:
Auth.currentUserCredentials() returns 一个未经身份验证的用户,已验证的 属性 设置为 false 和 400 错误,“ResourceNotFoundException: 身份池'eu-west-1:62dab5ed-5a84-4064-a7a2-87d1d0df511b'
系统:
- authenticationFlowType:“USER_SRP_AUTH”
- 版本:“aws-amplify”:“^3.3.14”,“aws-amplify-vue”:“^2.1.4”,放大版本 4.42.0
配置
{
"authSelections": "userPoolOnly",
"resourceName": "testapp89e81d50",
"serviceType": "imported",
"region": "eu-west-1"
}
我明白你的意思,老实说,我无法真正向你展示明确的文档来准确说明为什么这行不通。关于 Cognito 和 Amplify 的 AWS 文档很难拼凑在一起,因为 Amplify 框架仍然在后台使用旧库 ('amazon-cognito-identity-js'),而 Cognito 是 connect-login-with-IAM 和 signup/signin-as-a-service 奉献。如果做得好,Cognito 在安全性方面非常强大和坚如磐石,但设置有点麻烦。
有一些文档,例如Amplify Auth here. You can see there that currentCredentials / currentUserCredentials gives you some object 的 API 文档,其中包含 'identitiId'。凭证,在 Amplify Auth 框架中,指的是引用 Cognito Identity 的 AWS IAM 凭证。
您似乎在使用 Amplify 登录 Cognito 用户池,使用 email/password。 Cognito 用户池可以连接到 Cognito Identity 池,连接到 'exchange' Cognito JWT 令牌以获得一些可用于使用 AWS 资源的凭证(IAM 凭证)。不过,正常登录/注册流程不需要这样做。
所以,问题是:你想要什么?
您想了解当前登录 Cognito 用户池的用户吗,例如他的电子邮件、JWT 令牌和存储在 JWT 令牌中的其他字段?使用 'currentUserInfo' 或 'currentUserSession'
您真的想要一些 IAM 凭证来调用 AWS 资源吗?确保创建您的 Cognito 用户池并将其与 Cognito 身份池连接,并在您的前端设置中配置您的身份池 ID。如果你这样做了,你应该可以使用 'currentCredentials'.
在 Auth.signIn() 之后调用 Auth.currentUserCredentials() 时,我获得了有效的凭据,但对于未经身份验证的用户,为什么?
代码:
async signIn({ dispatch, state }, { email, password }) {
try {
const user = await Auth.signIn(email, password);
console.log("User state after login")
const userCredentialsAfterLogin = await Auth.currentUserCredentials();
console.log(userCredentialsAfterLogin)
} catch (error) {
console.log("error")
console.log(error)
return
}
await dispatch('fetchUser')
},
预期行为:
使用有效用户登录后,Auth.currentUserCredentials() 应该 return 一组经过身份验证的凭据。
实际行为:
Auth.currentUserCredentials() returns 一个未经身份验证的用户,已验证的 属性 设置为 false 和 400 错误,“ResourceNotFoundException: 身份池'eu-west-1:62dab5ed-5a84-4064-a7a2-87d1d0df511b'
系统:
- authenticationFlowType:“USER_SRP_AUTH”
- 版本:“aws-amplify”:“^3.3.14”,“aws-amplify-vue”:“^2.1.4”,放大版本 4.42.0
配置
{
"authSelections": "userPoolOnly",
"resourceName": "testapp89e81d50",
"serviceType": "imported",
"region": "eu-west-1"
}
我明白你的意思,老实说,我无法真正向你展示明确的文档来准确说明为什么这行不通。关于 Cognito 和 Amplify 的 AWS 文档很难拼凑在一起,因为 Amplify 框架仍然在后台使用旧库 ('amazon-cognito-identity-js'),而 Cognito 是 connect-login-with-IAM 和 signup/signin-as-a-service 奉献。如果做得好,Cognito 在安全性方面非常强大和坚如磐石,但设置有点麻烦。
有一些文档,例如Amplify Auth here. You can see there that currentCredentials / currentUserCredentials gives you some object 的 API 文档,其中包含 'identitiId'。凭证,在 Amplify Auth 框架中,指的是引用 Cognito Identity 的 AWS IAM 凭证。
您似乎在使用 Amplify 登录 Cognito 用户池,使用 email/password。 Cognito 用户池可以连接到 Cognito Identity 池,连接到 'exchange' Cognito JWT 令牌以获得一些可用于使用 AWS 资源的凭证(IAM 凭证)。不过,正常登录/注册流程不需要这样做。
所以,问题是:你想要什么?
您想了解当前登录 Cognito 用户池的用户吗,例如他的电子邮件、JWT 令牌和存储在 JWT 令牌中的其他字段?使用 'currentUserInfo' 或 'currentUserSession'
您真的想要一些 IAM 凭证来调用 AWS 资源吗?确保创建您的 Cognito 用户池并将其与 Cognito 身份池连接,并在您的前端设置中配置您的身份池 ID。如果你这样做了,你应该可以使用 'currentCredentials'.