I’ve been trying to authenticate user with Facebook and Twitter on iOS with Amazon Cognito. I can’t implement because Official documents is old.
Here is my code:
NSString *token = [FBSDKAccessToken currentAccessToken].tokenString;
credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionAPNortheast1 identityPoolId:IDENTITY_POOL_ID];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionAPNortheast1
credentialsProvider:credentialsProvider];
credentialsProvider.logins = @{ AWSIdentityProviderFacebook: token };
NSLog(@"credentialsProvider.logins : %@", credentialsProvider.logins);
[AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
But Xcode says that ‘logins’ is deprecated: Use “AWSIdentityProviderManager” to provide a valid logins dictionary to the credentials provider
I figured out that credentialsProvider.logins returns [null] as logins is deprecated.
Amazon official documents (English, Japanese) & samples are not up-to-date so I don’t know how to implement correctly to authenticate user.
Finally, I found a solution for this in Swift but I don’t know.
AWS Cognito Swift credentials provider "logins is deprecated: Use AWSIdentityProviderManager"
import Foundation
import AWSCore
import AWSCognito
import AWSCognitoIdentityProvider
class CustomIdentityProvider: NSObject, AWSCognitoIdentityProviderManager{
var tokens : [NSString : NSString]?
init(tokens: [NSString : NSString]) {
self.tokens = tokens
}
@objc func logins() -> AWSTask {
return AWSTask(result: tokens)
}
}
let customProviderManager = CustomIdentityProvider(tokens: logins!)
self.credentialsProvider = AWSCognitoCredentialsProvider(
regionType: Constants.COGNITO_REGIONTYPE,
identityPoolId: Constants.COGNITO_IDENTITY_POOL_ID,
identityProviderManager: customProviderManager)
Could you convert these codes to Objective-C and tell me how to use converted codes in my above code? Or please tell me the official recommended code?
same issue here:||
I read the the solution example you posted, and I found that there is an updated example
Updated Example Link
The updated example is implement in Swift but this issue they solved and implemented by Object-C. Check the folder "DeveloperAuthenticated" in the updated example.
Finally I figured out how to solve this issue a few days ago.
1.Add this class written in Swift to your Objc project.
2.In your view controller.
3.Initialze AWSCognitoCredentialsProvider with MyProvider that should be initialized with tokens.
*If you want to write MyProvider in Objc. According to
{yourProjectName}-Swift.h
which is created once you add Swift file, Maybe this should work? I haven't inspect if this code works though.I spent plenty of time to make it work. so I hope this post gonna be helpful for someone who have the same issue! thanks.