Skip to content

Instantly share code, notes, and snippets.

@davidtucker
Created May 11, 2017 01:16
Show Gist options
  • Save davidtucker/432627e8c5b9ea9f547c003d28aaab05 to your computer and use it in GitHub Desktop.
Save davidtucker/432627e8c5b9ea9f547c003d28aaab05 to your computer and use it in GitHub Desktop.
Cognito Configuration with the AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// setup logging for AWS & Cognito
AWSDDLog.sharedInstance.logLevel = .verbose
AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
// setup cognito config
self.cognitoConfig = CognitoConfig()
// setup cognito
setupCognitoUserPool()
return true
}
func setupCognitoUserPool() {
// we pull the needed values from the CognitoConfig object
// this just pulls the values in from the plist
let clientId:String = self.cognitoConfig!.getClientId()
let poolId:String = self.cognitoConfig!.getPoolId()
let clientSecret:String = self.cognitoConfig!.getClientSecret()
let region:AWSRegionType = self.cognitoConfig!.getRegion()
// we need to let Cognito know which region we plan to connect to
let serviceConfiguration:AWSServiceConfiguration = AWSServiceConfiguration(region: region, credentialsProvider: nil)
// we need to pass it the clientId and clientSecret from the app and the poolId for the user pool
let cognitoConfiguration:AWSCognitoIdentityUserPoolConfiguration = AWSCognitoIdentityUserPoolConfiguration(clientId: clientId, clientSecret: clientSecret, poolId: poolId)
AWSCognitoIdentityUserPool.register(with: serviceConfiguration, userPoolConfiguration: cognitoConfiguration, forKey: userPoolID)
let pool:AWSCognitoIdentityUserPool = AppDelegate.defaultUserPool()
// we need to set the AppDelegate as the user pool's delegate which will get called when events occur
pool.delegate = self
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment