csi*_*ilk 7 javascript amazon-web-services amazon-cognito aws-lambda
我正在使用 aws lambdas、dynamodb 和 cognito 构建身份验证系统。
坚持比较 getOpenIdTokenForDeveloperIdentity() 提供的令牌;调用来自服务器的特定身份。
我正在通过以下方式获取令牌和身份:
function getToken(email, fn) {
var param = {
IdentityPoolId: cognitoIdentityPoolId,
Logins: {} // To have provider name in a variable
};
param.Logins[cognitoDeveloperProvidedName] = email;
cognitoidentity.getOpenIdTokenForDeveloperIdentity(param,
function(err, data) {
if (err) return fn(err); // an error occurred
else fn(null, data.IdentityId, data.Token); // successful response
});
}
Run Code Online (Sandbox Code Playgroud)
然后据我所知,我可以从 cognito 中获取已经生成的令牌(而不是创建一个新令牌),如下所示:
function checkToken(IdentityId, email, fn){
var param = {
IdentityPoolId: cognitoIdentityPoolId,
IdentityId: IdentityId,
Logins: {}
};
param.Logins[cognitoDeveloperProvidedName] = email;
cognitoidentity.getCredentialsForIdentity(param,
function(err, data) {
if (err) return fn(err);
else fn(null, data);
});
}
Run Code Online (Sandbox Code Playgroud)
但我似乎无法让它工作
有任何想法吗?
弄清楚了,checkToken 函数需要如下所示:
function checkToken(providedIdentity, token, fn){
var param = {
IdentityId: providedIdentity,
Logins: {}
};
param.Logins['cognito-identity.amazonaws.com'] = token;
cognitoidentity.getCredentialsForIdentity(param,
function(err, data) {
if (err) return fn(err);
else fn(null, data);
});
}
Run Code Online (Sandbox Code Playgroud)
我需要将 cognito-identity.amazonaws.com 设置为登录提供程序
| 归档时间: |
|
| 查看次数: |
2715 次 |
| 最近记录: |