Aws Cognito Credentialsprovider.Login Always Shows Nil (Swift)

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:

  1. 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.
  2. 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.
  3. 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



Leave a reply



Submit