AWS Cognito Swift credentials provider logins is deprecated: Use AWSIdentityProviderManager
After looking around I finally found out I wasn't the only one with this issue. AWS updated their sdk without changing their main documentation.
The solution is to implement the AWSCognitoIdentityProviderManager in a custom class and feed that to the credentials provider.
Heres the code provided by simaomi in the github discussion below (its more of a quick fix):
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)
the sdk example shows how you should really implement the solution
Look here for the discussion:
https://github.com/aws/aws-sdk-ios/issues/357
and here for updated sdk examples:
https://github.com/awslabs/aws-sdk-ios-samples/tree/developer-authenticated-identities-2-4/CognitoSync-Sample
[iOS][AWS Cognito] 'logins' is deprecated: Use AWSIdentityProviderManager
Finally I figured out how to solve this issue a few days ago.
1.Add this class written in Swift to your Objc project.
// CognitoCustomProviderManager.swift
import Foundation
import AWSCognitoIdentityProvider
class MyProvider:NSObject, AWSIdentityProviderManager{
var tokens : [NSString : NSString]?
init(tokens: [NSString : NSString]) {
self.tokens = tokens
print("tokens : ", self.tokens);
}
@objc func logins() -> AWSTask {
return AWSTask(result: tokens)
}
}
2.In your view controller.
@property MyProvider *myProvider;
3.Initialze AWSCognitoCredentialsProvider with MyProvider that should be initialized with tokens.
MyProvider *Provider = [[MyProvider alloc] initWithTokens:@{AWSIdentityProviderFacebook : token }];
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:COGNITO_REGION_TYPE identityPoolId:IDENTITY_POOL_ID identityProviderManager:Provider];
*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.
@interface MyProvider : NSObject <AWSIdentityProviderManager>
@property (nonatomic, copy) NSDictionary<NSString *, NSString *> * _Nullable tokens;
- (nonnull instancetype)initWithTokens:(NSDictionary<NSString *, NSString *> * _Nonnull)tokens OBJC_DESIGNATED_INITIALIZER;
- (AWSTask * _Nonnull)logins;
@end
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.
How to add a logins map to CredentialsProvider?
You do not add the logins
dictionary to the credentials provider. AWSIdentityProviderManager
defines the following method:
- (AWSTask<NSDictionary<NSString *, NSString *> *> *)logins;
It asynchronously supplies the logins
dictionary to the credentials provider, and AWSCognitoIdentityUserPool
conforms to AWSIdentityProviderManager
. So, the code snippet is all you need. If you are experiencing an issue, it is not related to the logins
dictionary.
ios swift AWS cognito and Facebook Authentication
Solved my problem somehow. All I did was deleted my identity pool and Facebook app and created new ones. It is now working fine.
Related Topics
How to Silence a Warning in Swift
Get Description of Emoji Character
Nsfontattributedstring Worked Before Xcode 6.1
In Xcode 6.1. 'Uiimage' Does Not Have a Member Named 'Size' Error
Access Input from Uialertcontroller
How to Set Collection View's Cell Size via the Auto Layout
Different Ways to Initialize a Dictionary in Swift
Swift: Orient Y-Axis Toward Another Point in 3-D Space
How to Cycle Through the Entire Alphabet with Swift While Assigning Values
Arkit - How to Export Obj from Iphone/iPad with Lidar
Include Swiftui Views in Existing Uikit Application
Reference to Property in Closure Requires Explicit 'Self.' to Make Capture Semantics Explicit
Swift5 Macos Imageresize Memory Issue
Swift 2.1 [Uint8] --Utf8--> String
Hide Navigation Bar Without Losing Swipe Back Gesture in Swiftui
Swift Generics: Requiring Addition and Multiplication Abilities of a Type
Nsimage to Nsdata as Png Swift
Apply a Shadow on a Uiview That Have Same Corner Radius Than View