[英]AWS: How to properly authenticate a user against Cognito Pool and use it for Cognito Federated Identity?
[英]AWS Cognito Federated Identity Pool - Role on Authentication
我有2個身份池-一個用於Unauth(僅設置了Unauth角色),另一個用於聯合身份(FB和Google-僅設置了Auth角色)。
我有一個iOS應用程序,其中包含2個實現AWSIdentityProviderManager協議的類-GuestProvider返回一個空的登錄名,而FBProvider填充登錄名中的FB令牌。
當我啟動該應用程序並以訪客身份瀏覽時,它可以工作。類似地,如果我啟動該應用程序並直接登錄FB,它也可以使用適當的身份驗證角色。
當我以來賓身份登錄然后切換到FB時,問題就來了-盡管我獲得了Auth令牌並將其設置在Provider中並更新defaultServiceConfiguration,但是Lambda調用失敗並出現AccessDenied錯誤-日志顯示它仍然具有unauth角色。 如果我啟動應用程序並通過FB登錄(不會先去訪客),則不會發生這種情況。
這些是用於為用例設置AWS配置的功能:
func initializeGuestCredentialsProvider() {
// AWS
credentialsProvider = AWSCognitoCredentialsProvider(
regionType: Constants.AWS_REGION,
identityPoolId: Constants.COGNITO_UNAUTH_IDENTITY_POOL_ID);
let configuration = AWSServiceConfiguration(
region: Constants.AWS_REGION,
credentialsProvider: credentialsProvider
);
AWSServiceManager.default().defaultServiceConfiguration = configuration
}
func initializeFBCredentialsProvider() {
credentialsProvider = AWSCognitoCredentialsProvider(
regionType: Constants.AWS_REGION,
identityPoolId: Constants.COGNITO_IDENTITY_POOL_ID,
identityProviderManager: FacebookProvider());
let configuration = AWSServiceConfiguration(
region: AWSRegionType.USWest2,
credentialsProvider: credentialsProvider
);
AWSServiceManager.default().defaultServiceConfiguration = configuration
}
我不確定導致此錯誤的原因是什么。 可能是第一個在config中設置的憑據提供程序,不能更改嗎?
我建議使用一個身份池。 當用戶從Guest切換到Authenticated時,只需將identityId和提供者令牌(在登錄映射中)傳遞給GetCredentialsForIdentity。 這會將相同的identityId鏈接到提供者(Facebook)用戶。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.