AWSCognitoAuth Class Reference

Inherits from NSObject
Declared in AWSCognitoAuth.h
AWSCognitoAuth.m

Overview

A lightweight web-based ui to manage signup/signin of your end users

Other Methods

  delegate

Set this delegate to obtain the current view controller to interact with the end user

@property (nonatomic, strong) id<AWSCognitoAuthDelegate> delegate

Declared In

AWSCognitoAuth.h

  authConfiguration

The auth configuration

@property (nonatomic, readonly) AWSCognitoAuthConfiguration *authConfiguration

Declared In

AWSCognitoAuth.h

  signedIn

Determines whether there is an active session or not. If the refresh token is expired the end user will be prompted to authenticate when you call getSession.

@property (nonatomic, readonly, getter=isSignedIn) BOOL signedIn

Declared In

AWSCognitoAuth.h

+ defaultCognitoAuth

Fetches the Cognito User Pool instance configured in the info.plist under AWS->CognitoUserPool->Default

+ (instancetype)defaultCognitoAuth

Return Value

the default instance for Cognito Auth

Declared In

AWSCognitoAuth.h

+ registerCognitoAuthWithAuthConfiguration:forKey:

Register a managed instance with name forKey and configuration authConfiguration.

+ (void)registerCognitoAuthWithAuthConfiguration:(AWSCognitoAuthConfiguration *)authConfiguration forKey:(NSString *)key

Parameters

authConfiguration

the auth configuration

key

the key to register under

Declared In

AWSCognitoAuth.h

+ CognitoAuthForKey:

Fetch a managed instance with a particular AuthConfiguration.

+ (instancetype)CognitoAuthForKey:(NSString *)key

Parameters

key

the key to fetch

Return Value

the CognitoAuth object

Declared In

AWSCognitoAuth.h

+ removeCognitoAuthForKey:

Unregister a managed instance.

+ (void)removeCognitoAuthForKey:(NSString *)key

Parameters

key

key to remove the object for

Declared In

AWSCognitoAuth.h

– getSession:completion:

Get a session with id, access and refresh tokens.

- (void)getSession:(UIViewController *)vc completion:(nullable AWSCognitoAuthGetSessionBlock)completion

Parameters

vc

viewController to display the UI on if needed during sign in.

completion

completion block to invoke on completion

Declared In

AWSCognitoAuth.h

– getSession:

Get a session with id, access and refresh tokens, use delegate to get view controller.

- (void)getSession:(nullable AWSCognitoAuthGetSessionBlock)completion

Parameters

completion

completion block to invoke on completion

Declared In

AWSCognitoAuth.h

– signOut:completion:

Sign out locally and from the server.

- (void)signOut:(UIViewController *)vc completion:(nullable AWSCognitoAuthSignOutBlock)completion

Parameters

vc

viewController to display the UI on during sign out.

completion

completion block to invoke on completion

Declared In

AWSCognitoAuth.h

– signOut:

Sign out locally and from the server, use delegate to get view controller.

- (void)signOut:(nullable AWSCognitoAuthSignOutBlock)completion

Parameters

completion

completion block to invoke on completion

Declared In

AWSCognitoAuth.h

– application:openURL:options:

Method to handle app redirect. Call from AppDelegate application:openURL:options

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options

Declared In

AWSCognitoAuth.h

Other Methods

– enqueueGetSession:completion:

Adds another getSession operation to the serialized queue of getSession requests

- (void)enqueueGetSession:(nullable UIViewController *)vc completion:(AWSCognitoAuthGetSessionBlock)completion

Declared In

AWSCognitoAuth.m

– cleanupSignIn

Cleanup resources from the sign in attempt

- (void)cleanupSignIn

Declared In

AWSCognitoAuth.m

– launchSignInVC:

Launch the sign in ui on the provided viewcontroller

- (void)launchSignInVC:(UIViewController *)vc

Declared In

AWSCognitoAuth.m

– getSessionInternal:completion:

Check keychain for valid session, if expired or not available, prompt end user via ui

- (void)getSessionInternal:(nullable UIViewController *)vc completion:(AWSCognitoAuthGetSessionBlock)completion

Declared In

AWSCognitoAuth.m

– completeGetSession:error:

Dismiss ui, invoke completion and cleanup a getSession call.

- (void)completeGetSession:(nullable AWSCognitoAuthUserSession *)userSession error:(nullable NSError *)error

Declared In

AWSCognitoAuth.m

– completeSignOut:

Dismiss ui, invoke completion and cleanup a signOut call.

- (void)completeSignOut:(nullable NSError *)error

Declared In

AWSCognitoAuth.m

– signOutInternal:completion:

Display ui for signout

- (void)signOutInternal:(UIViewController *)vc completion:(AWSCognitoAuthSignOutBlock)completion

Declared In

AWSCognitoAuth.m

– signOutLocally

Remove user session from keychain

- (void)signOutLocally

Declared In

AWSCognitoAuth.m

– signOutLocallyAndClearLastKnownUser

Remove user session from keychain and clear last known username.

- (void)signOutLocallyAndClearLastKnownUser

Declared In

AWSCognitoAuth.m

– getDateFormatter

Obtain a date formatter for this format: yyyy-MM-dd’T'HH:mm:ss'Z'

- (NSDateFormatter *)getDateFormatter

Declared In

AWSCognitoAuth.m

– dateFromString:

Convert a string to date

- (NSDate *)dateFromString:(NSString *)string

Declared In

AWSCognitoAuth.m

– stringValue:

Convert a string to date

- (NSString *)stringValue:(NSDate *)date

Declared In

AWSCognitoAuth.m

– safariViewControllerDidFinish:

Delegate callback called when the user taps the Done button. Upon this call, the view controller is dismissed modally.

- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller

Declared In

AWSCognitoAuth.m

– safariViewController:didCompleteInitialLoad:

Invoked when the initial URL load is complete.

- (void)safariViewController:(SFSafariViewController *)controller didCompleteInitialLoad:(BOOL)didLoadSuccessfully

Parameters

didLoadSuccessfully

YES if loading completed successfully, NO if loading failed.

Discussion

This method is invoked when SFSafariViewController completes the loading of the URL that you pass to its initializer. It is not invoked for any subsequent page loads in the same SFSafariViewController instance.

Declared In

AWSCognitoAuth.m

– generateRandom:

Generate a random number of size bytes and base64 encode it with a url safe encoding.

- (NSString *)generateRandom:(int)size

Declared In

AWSCognitoAuth.m

– calculateSHA256Hash:

Calculate a SHA256 Hash of a string and base64 encode it with a url safe encoding.

- (NSString *)calculateSHA256Hash:(NSString *)string

Declared In

AWSCognitoAuth.m

– urlSafeBase64:

Make a base64 encoded string url safe

- (NSString *)urlSafeBase64:(NSString *)string

Declared In

AWSCognitoAuth.m

– urlEncode:

Make a string url safe *

- (NSString *)urlEncode:(NSString *)stringToEncode

Declared In

AWSCognitoAuth.m

– addHeaders:

Add authorization and User-Agent header as appropriate.

- (void)addHeaders:(NSMutableURLRequest *)request

Declared In

AWSCognitoAuth.m

– dismissSafariVC

Dismiss and reap the safari view controller

- (void)dismissSafariVC

Declared In

AWSCognitoAuth.m

– clearAll

Removes everything from the keychain under this appClientId

- (void)clearAll

Declared In

AWSCognitoAuth.m

– keyChainKey:key:

Get a namespaced keychain key given a namespace and key

- (NSString *)keyChainKey:(NSString *)namespace key:(const NSString *)key

Declared In

AWSCognitoAuth.m

– updateUsernameAndPersistTokens:

Update the username and persist session tokens in the keychain

- (void)updateUsernameAndPersistTokens:(AWSCognitoAuthUserSession *)session

Declared In

AWSCognitoAuth.m

– getError:code:

Helper for getting errors

- (NSError *)getError:(NSString *)error code:(AWSCognitoAuthClientErrorType)code

Declared In

AWSCognitoAuth.m

– normalizeScopes

Sort scopes in lexigraphical order and join them with a space character.

- (NSString *)normalizeScopes

Declared In

AWSCognitoAuth.m

+ objectForKey:

Get an object from the instanceDictionary

+ (id)objectForKey:(id)aKey

Declared In

AWSCognitoAuth.m

+ removeObjectForKey:

Remove an object from the instanceDictionary

+ (void)removeObjectForKey:(id)aKey

Declared In

AWSCognitoAuth.m

+ setObject:forKey:

Set an object in the instanceDictionary

+ (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey

Declared In

AWSCognitoAuth.m

+ userAgent

Generate the user agent string

+ (NSString *)userAgent

Declared In

AWSCognitoAuth.m