I'm trying to integrate aws user pool in my project. I manage to do a normal login with email and password, but I need to add login in with Facebook.
From what I read in documentation, for this I need to create an Indentity pool in Federated identities. I create one and I add the follow configurations for Authentication providers: - in Facebook tab to add my Facebook App ID, - and in Cognito tab to add my user pool id and app client id for my user pool.
And inside of my user pool, In Identity providers from federation, I select Facebook and for this I add my Facebook app ID and App secret.
In my app I implement a AWSIdentityProviderManager that contain:
class CognitoSocialProvider: AWSIdentityProviderManager {
func logins() -> AWSTask<NSDictionary> {
if let token = FBSDKAccessToken.current() {
return AWSTask(result: [AWSIdentityProviderFacebook:token.tokenString])
}
return AWSTask(error:NSError(domain: kCognitoFacebookDomainError, code: -1 , userInfo: [kCognitoFaceook : kCognitoFacebookInvalidAccessToken]))
}
}
And here is my code for Facebook login:
let loginManager = FBSDKLoginManager()
let permisions = [kCognitoFacebookPublicProfil, kCognitoFacebookEmail]
loginManager.logIn(withReadPermissions: permisions,
from: parentVC) { (result, error) in
if (error != nil) {
failure(error! as NSError)
} else if (result?.isCancelled == true){
failure(NSError())
} else {
let socialProvider = CognitoSocialProvider()
provider = AWSCognitoCredentialsProvider(regionType: REGION,
identityPoolId: IDENTITY_POOL,
identityProviderManager: socialProvider)
let serviceConfiguration = AWSServiceConfiguration(region: REGION, credentialsProvider: provider)
AWSServiceManager.default().defaultServiceConfiguration = serviceConfiguration
provider.clearKeychain()
provider.clearCredentials()
provider.credentials().continueWith { (task) -> Any? in
DispatchQueue.main.async(execute: {
if let error = task.error as NSError? {
failure(error)
} else {
let response = task.result! as AWSCredentials
success(CognitoFacebookSession(credentials: response))
}
})
return nil
}
}
The login work, but when I look in my user pool in user an groups section, I can't see my user over there.
There is any other solution to integrate Facebook login, using only user pool without using Identity pool?