我在客户端上使用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