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
AWS Cognito does not create Twitter/Digit login when called from Swift
The AWSCognitoCredentialsProvider is lazily loaded. Simply setting the logins dictionary is not enough to cause a login to appear in the console. Please try one of the following:
- You can use the credentials provider to access any other service, for instance using the Amazon Cognito Sync service to store information for the identity and synchronize to the cloud.
- You can also force the credentials provider to make a call to the Amazon Cognito Identity service. If you do not have a cached identity id, the
getIdentitId
method will make a call to the service to establish your identityId. - If you already have an identity cached, you can use the
refresh
method to force re-authentication with the contents of the logins dictionary.
AWS Cognito Only Working in USEast1
Typically, after struggling with this for several days I've figured out the problem having finally posted to SO.
The problem was that there was a previous version of the AWS iOS SDK linked on the Framework Search Paths, which did not have EUCentral1. The inclusion of that in the enum appears to have changed the indexes and given that Cognito is only supported in USEast1 and EUWest1 it was attempting to authenticate against an incorrect region.
Receiving Missing credentials in config when using AWS.CognitoIdentityCredentials
Are you making the following call to get the credentials?
// Make the call to obtain credentials
AWS.config.credentials.get(function(){
// Credentials will be available when this function is called.
var accessKeyId = AWS.config.credentials.accessKeyId;
var secretAccessKey = AWS.config.credentials.secretAccessKey;
var sessionToken = AWS.config.credentials.sessionToken;
// Add your code here that uses the credentials
});
// Do NOT assume that the credentials are valid here
Note: The credentials are not available until the callback function is called. A common mistake is writing code outside of the callback assuming that the credentials exist immediately after calling AWS.config.credentials.get().
Related Topics
Swift: Get The Compile Time Name of Variable (Referencing to a Class)
Swift Preserve UIswitch State on UIlongpress
Swift: Trunc a Floating Number to Show It in a Label
Swiftui New App Lifecycle How to Connect The Facebook Sdk
Why Is This Predicate Format Being Turned into '= Nil'
How to Get a Full List of Running Processes
Swift - Connect Delegate to Custom Xib Cell
Applying Impulses in Spritekit
Convert Input Data to Integer in Swift
Apple Mach-O Linker Error (Static, Not Ld)
List Scroll Freeze on Catalyst Navigationview
Macos App Sandboxing - Read Access to Referenced Files from Parsed Xml
Parse Weird Bug in Swift That Causes Acl Write Permissions to Change to an Objectid
How to Loop Over The Output of a Publisher with Combine
Apple's Swift Compiler Complains of Partial Application When Creating Extension Method on Array
iOS-Charts Error: Thread1: Exc_Bad_Access (Code=2, Address=0X2A0C220)