簡體   English   中英

使用AWS Cognito,我可以在給定禁用的未經身份驗證的IdentityId的情況下解析經過身份驗證的IdentityId嗎?

[英]Using AWS Cognito can I resolve the authenticated IdentityId given a disabled unauthenticated IdentityId?

我有一個JavaScript Web應用程序,支持Cognito未經身份驗證的身份。 我試圖找出如何識別已DISABLED未經身份驗證的IdentityId的鏈接身份驗證IdentityId。

首先通過AWS.config.credentials.get向未經身份驗證的用戶頒發IdentityId。 內部CognitoIdentityCredentials使用getId生成新的未經身份驗證的IdentityId。

let unathenticatedIdentityId;

const AWS = require('aws-sdk');
AWS.config.region = region;
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId
});
AWS.config.credentials.get(err => {
    unathenticatedIdentityId = AWS.config.credentials.identityId;
});

然后,我們的用戶通過amazon-cognito-identity-js向Cognito用戶池進行amazon-cognito-identity-js驗證,未經身份驗證的IdentityId將更改為與其Cognito Login相關聯的經過身份驗證的IdentityId。 未經身份驗證的IdentityId會自動標記為DISABLED並在內部鏈接到經過身份驗證的IdentityId。

let authenticatedIdentityId;

const { CognitoUserPool, CognitoUser, AuthenticationDetails } = require('amazon-cognito-identity-js');
const Pool = new CognitoUserPool({
    UserPoolId,
    ClientId,
});
const authDetails = new AuthenticationDetails({
    Username,
    Password,
});
const user = new CognitoUser({
    Pool,
    Username,
});
user.authenticateUser(authDetails, {
    onSuccess: (session) => {
        AWS.config.credentials.params.Logins = {
            [PoolProviderName]: session.idToken.jwtToken,
        };
        AWS.config.credentials.expired = true;

        AWS.config.credentials.refresh(err => {
            authenticatedIdentityId = AWS.config.credentials.identityId;
        });
    },
});

我有unathenticatedIdentityIdauthenticatedIdentityId的值,但我沒有在AWS Cognito API中看到解決DISABLED unauthenticatedIdentityId已鏈接到authenticatedIdentityId 相反,我沒有找到識別IdentityIds鏈接到authenticatedIdentityId describeIdentity API將告訴我unauthenticatedIdentityIdDISABLED並且它沒有Logins ,但它沒有指向鏈接的authenticatedIdentityId

如何使用linked / DISABLED unauthenticatedIdentityId的值來解析值authenticatedIdentityId

我有一個使用AWS Cognito獲取身份ID的應用程序,然后可能對其進行身份驗證。 情況是客戶端首先使用應用程序作為未經身份驗證的(訪客),然后使用Facebook登錄,使他/她自己經過身份驗證,並且AWS為經過身份驗證的用戶保留給定的身份ID,因為他是新用戶。 現在,當您退出應用程序並且其他人想要將此應用程序用作未經身份驗證或甚至經過身份驗證時,問題就出現了。 Cognito將錯誤地說禁止訪問身份ID,因為它已經鏈接到以前用戶的Facebook帳戶。

Cognito移動SDK有內置的方法來處理這個問題。 它們在使用時會緩存身份ID,這會導致您看到的問題。 當您注銷時,您將要清除該緩存。 我不確定您使用的是哪個SDK,但在iOS中它是Android中的AWSCognitoIdentityProvider.clear()CognitoCachingCredentialsProvider.clear() 同樣,如果您正在使用Cognito Sync ,那么該客戶端中的方法將擦除緩存的ID和同步數據。

另請查看https://aws.amazon.com/blogs/mobile/understanding-amazon-cognito-authentication/

希望您也關注https://aws.amazon.com/blogs/mobile/using-the-amazon-cognito-credentials-provider/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM