Aws Cognito Swift Credentials Provider "Logins Is Deprecated: Use Awsidentityprovidermanager"

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



Leave a reply



Submit