我在客戶端上使用Facebook登錄和AWS Cognito建立了身份驗證流程。我需要用戶在其dynambodb表中使用其facebook代碼的引用,並驗證API調用實際上是否有一個有效的Facebook ID,此Facebook ID與AWS Cognito Id匹配。 我在這個答案中找到了一個解決方案:AWS Cognito, Lambda, User credentials in DynamoDBAWS Cognito更改中的身份標識
但我在Cognito登錄多次後,在同一臺設備上,我發現在控制檯中有幾個不同的身份標識。像這樣: screen shot
我認爲身份證對於某個具有某個Facebook ID的設備是唯一的。我犯了一些錯誤嗎?如果身份標識發生變化,我如何將用戶的數據存儲在dynamoDB中?
這是我的代碼:
void Start()
{
InitCognito();
}
public void InitCognito()
{
UnityInitializer.AttachToGameObject (this.gameObject);
credentials = new CognitoAWSCredentials (
identity_pool_id, // Identity Pool ID
region // Region
);
Debug.Log ("identity_pool_id = " + identity_pool_id + " region = " + region);
credentials.GetIdentityIdAsync(delegate(AmazonCognitoIdentityResult<string>
result) {
if (result.Exception != null) {
Debug.LogError(result.Exception.ToString());
}
string identityId = result.Response;
Debug.Log("identityId = "+identityId);
FBInit();
});
}
public void FBInit()
{
FB.Init(this.OnInitComplete, this.OnHideUnity);
Debug.Log("FB.Init() called with " + FB.AppId);
}
public void FBLogin()
{
FB.LogInWithReadPermissions(new List<string>() { "public_profile", "email", "user_friends" }, this.HandleResult);
}
private void OnInitComplete()
{
Debug.Log("Success - Check log for details");
Debug.Log("Success Response: OnInitComplete Called\n");
Debug.Log(string.Format(
"OnInitCompleteCalled IsLoggedIn='{0}' IsInitialized='{1}'",
FB.IsLoggedIn,
FB.IsInitialized));
if (AccessToken.CurrentAccessToken != null)
{
Debug.Log("Access token = "+AccessToken.CurrentAccessToken.ToString());
}
FBLogin();
}
private void OnHideUnity(bool isGameShown)
{
Debug.Log("Success - Check log for details");
Debug.Log(string.Format("Success Response: OnHideUnity Called {0}\n", isGameShown));
Debug.Log("Is game shown: " + isGameShown);
}
protected void HandleResult(IResult result)
{
if (result == null)
{
Debug.Log("Null Response\n");
return;
}
// Some platforms return the empty string instead of null.
if (!string.IsNullOrEmpty(result.Error))
{
Debug.Log("Error - Check log for details");
Debug.Log("Error Response:\n" + result.Error);
}
else if (result.Cancelled)
{
Debug.Log ("Cancelled - Check log for details");
Debug.Log("Cancelled Response:\n" + result.RawResult);
}
else if (!string.IsNullOrEmpty(result.RawResult))
{
Debug.Log ("Success - Check log for details");
Debug.Log ("Success Response:\n" + result.RawResult);
Debug.Log ("Access Token = "+AccessToken.CurrentAccessToken);
Debug.Log ("Access Token = "+AccessToken.CurrentAccessToken.TokenString);
Debug.Log ("Access User Id =" + AccessToken.CurrentAccessToken.UserId);
credentials.AddLogin ("graph.facebook.com", AccessToken.CurrentAccessToken.TokenString);
if (credentials.CurrentLoginProviders.Length > 0) {
Debug.Log (credentials.CurrentLoginProviders[0]);
}
Debug.Log (credentials.GetCachedIdentityId());
}
else
{
Debug.Log ("Empty Response\n");
}
}
當執行InitCognito()方法中,我得到一個未經授權的身份標識(一旦我重新安裝了相同的設備,未經授權身份標識的變化對這個應用程序)。我可以成功獲取Facebook用戶標識和令牌。執行credentials.AddLogin()方法後,Debug.Log(credentials.GetCachedIdentityId())顯示身份標識與未經授權的身份標識相同,而不是引用到Facebook標識的特定標識。我是否以錯誤的方式使用credentials.AddLogin()?
謝謝!
點擊這些身份。他們有登錄鏈接到他們嗎? –
其中兩個已連接登錄。 「鏈接登錄」字段在第一個字段中顯示「graph.facebook.com」,在第二個字段中顯示「DISABLED us-east-1」。 – DogJunior