AWSCognitoAuth

@interface AWSCognitoAuth : NSObject

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

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

    Declaration

    Objective-C

    @property (readwrite, nonatomic) id<AWSCognitoAuthDelegate> _Nullable delegate;

    Swift

    weak var delegate: AWSCognitoAuthDelegate? { get set }
  • The auth configuration

    Declaration

    Objective-C

    @property (readonly, nonatomic)
        AWSCognitoAuthConfiguration *_Nonnull authConfiguration;

    Swift

    var authConfiguration: AWSCognitoAuthConfiguration { get }
  • 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.

    Declaration

    Objective-C

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

    Swift

    var isSignedIn: Bool { get }
  • Fetches the Cognito User Pool instance configured in the info.plist under AWS->CognitoUserPool->Default

    Declaration

    Objective-C

    + (nonnull instancetype)defaultCognitoAuth;

    Swift

    class func `default`() -> Self

    Return Value

    the default instance for Cognito Auth

  • Register a managed instance with name forKey and configuration authConfiguration.

    Declaration

    Objective-C

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

    Swift

    class func registerCognitoAuth(with authConfiguration: AWSCognitoAuthConfiguration, forKey key: String)

    Parameters

    authConfiguration

    the auth configuration

    key

    the key to register under

  • Fetch a managed instance with a particular AuthConfiguration.

    Declaration

    Objective-C

    + (nonnull instancetype)CognitoAuthForKey:(nonnull NSString *)key;

    Swift

    convenience init(forKey key: String)

    Parameters

    key

    the key to fetch

    Return Value

    the CognitoAuth object

  • Unregister a managed instance.

    Declaration

    Objective-C

    + (void)removeCognitoAuthForKey:(nonnull NSString *)key;

    Swift

    class func remove(forKey key: String)

    Parameters

    key

    key to remove the object for

  • Get a session with id, access and refresh tokens.

    Declaration

    Objective-C

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

    Swift

    func getSession(_ vc: UIViewController, completion: AWSCognitoAuthGetSessionBlock? = nil)

    Parameters

    vc

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

    completion

    completion block to invoke on completion

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

    Declaration

    Objective-C

    - (void)getSession:(nullable AWSCognitoAuthGetSessionBlock)completion;

    Swift

    func getSession(_ completion: AWSCognitoAuthGetSessionBlock? = nil)

    Parameters

    completion

    completion block to invoke on completion

  • Sign out locally and from the server.

    Declaration

    Objective-C

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

    Swift

    func signOut(_ vc: UIViewController, completion: AWSCognitoAuthSignOutBlock? = nil)

    Parameters

    vc

    viewController to display the UI on during sign out.

    completion

    completion block to invoke on completion

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

    Declaration

    Objective-C

    - (void)signOut:(nullable AWSCognitoAuthSignOutBlock)completion;

    Swift

    func signOut(_ completion: AWSCognitoAuthSignOutBlock? = nil)

    Parameters

    completion

    completion block to invoke on completion

  • Remove user session from keychain

    Declaration

    Objective-C

    - (void)signOutLocally;

    Swift

    func signOutLocally()
  • Remove user session from keychain and clear last known username.

    Declaration

    Objective-C

    - (void)signOutLocallyAndClearLastKnownUser;

    Swift

    func signOutLocallyAndClearLastKnownUser()
  • Method to handle app redirect. Call from AppDelegate application:openURL:options

    Declaration

    Objective-C

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

    Swift

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool