1

我想將AWS Cognito集成到我的移動應用程序中並主要使用Facebook和Google登錄,並且一旦用戶登錄,他就可以從S3上載/下載文件並與其交互DynamoDB也是如此。我還希望特定用戶的cognitoID成爲DynamoDB中識別每個用戶的主鍵。 首先,這是一個好主意,保持用戶識別每個用戶的認證ID(IdentityID)?使用Cognito通過Facebook登錄後無法獲取身份ID

其次,當我嘗試使用getIdentityID從sharedInstance拿到身份ID,在以下

// Retrieve your Amazon Cognito ID 
credentialsProvider.getIdentityId().continueWithBlock { (task: AWSTask!) -> AnyObject! in 
if (task.error != nil) { 
print("Error: " + task.error.localizedDescription) 
} 
else { 
// the task result will contain the identity id 
let cognitoId = task.result 
} 
return nil 
} 

的行或多或少我沒有得到所需要的IdentityID,而是我得到一個零和因此不能堅持。 我錯過了什麼嗎? 如果您需要更多信息,請讓我知道。

回答

1

如果你不打算合併登錄,那應該是絕對安全的。一旦通過身份驗證,唯一一次身份可能發生變化的情況是登錄被合併。如果是這樣,仍然可以使用您構建的掛鉤進行管理,該掛鉤將數據從舊標識標識移至新標識。

這對我來說看起來很好(這正是啓動代碼的示例)。根據the Cognito docs,getIdentityId是異步調用。如果您的提供商已經設置了身份標識,則可以調用credentialsProvider.identityId來檢索該身份,該身份將在本地緩存。但是,如果您的提供者沒有設置身份標識,則調用credentialsProvider.identityId將返回nil。我猜你的問題是這樣的。

如果你確信這不是問題,我想證實,在我們的文檔的例子,以及客戶端被初始化:

 
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: AWSRegionType.USEast1, identityPoolId: "IDENTITY_POOL_ID") 
let configuration = AWSServiceConfiguration(region: AWSRegionType.USEast1, credentialsProvider: credentialsProvider) 
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration 
+0

我使用ClientManager作爲 [鏈接](HTTPS給出://github.com/awslabs/aws-sdk-ios-samples/blob/master/CognitoSync-Sample/Swift/CognitoSyncDemo/AmazonClientManager.swift) 在我的項目中,這裏上面的代碼在功能 initializeClients 。 並在一些其他viewController訪問身份ID我嘗試了兩個 AmazonClientManager.sharedInstance.credentialsProvider?.identityId和我的問題給出的,都給我零。 –

+0

嘗試一些基本的東西。如上所述初始化客戶端,在該客戶端上調用刷新,等待幾秒鐘,然後檢查它。那麼它是否設置? –

相關問題