AWSCognitoAuth
Objective-C
@interface AWSCognitoAuth : NSObject
Swift
class 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 (nonatomic, weak) id<AWSCognitoAuthDelegate> _Nullable delegate;
Swift
weak var delegate: AWSCognitoAuthDelegate? { get set }
-
The auth configuration
Declaration
Objective-C
@property (nonatomic, readonly) 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 (nonatomic, readonly, getter=isSignedIn) BOOL signedIn;
Swift
var isSignedIn: Bool { get }
-
Fetches the Cognito User Pool instance configured in the
info.plist
underAWS->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
-
Launches the signin UI and updates the session after the user logs in.
Declaration
Objective-C
- (void)launchSignInWithViewController:(nonnull UIViewController *)vc completion:(nullable AWSCognitoAuthGetSessionBlock) completion;
Swift
func launchSignIn(with vc: UIViewController) async throws -> AWSCognitoAuthUserSession
Parameters
vc
Presentation view controller to display the hosted UI signIn
completion
completion block to invoke on completion
-
Launches the signin UI and updates the session after the user logs in.
Declaration
Objective-C
- (void)launchSignInWithWebUI:(nonnull ASPresentationAnchor)anchor completion: (nullable AWSCognitoAuthGetSessionBlock)completion;
Swift
func launchSignIn(withWebUI anchor: ASPresentationAnchor) async throws -> AWSCognitoAuthUserSession
Parameters
anchor
Presentation anchor to display the hosted UI signIn
completion
completion block to invoke on completion
-
Get a session with id, access and refresh tokens.
Declaration
Objective-C
- (void)getSessionWithWebUI:(nonnull ASPresentationAnchor)anchor completion:(nullable AWSCognitoAuthGetSessionBlock)completion;
Swift
func session(withWebUI anchor: ASPresentationAnchor) async throws -> AWSCognitoAuthUserSession
Parameters
anchor
Presentation anchor to display the hosted UI on if needed during sign in.
completion
completion block to invoke on completion
-
Get a session with id, access and refresh tokens.
Declaration
Objective-C
- (void)getSession:(nonnull UIViewController *)vc completion:(nullable AWSCognitoAuthGetSessionBlock)completion;
Swift
func session(_ vc: UIViewController) async throws -> AWSCognitoAuthUserSession
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 session() async throws -> AWSCognitoAuthUserSession
Parameters
completion
completion block to invoke on completion
-
Undocumented
Declaration
Objective-C
- (void) signOutWithWebUI:(nonnull ASPresentationAnchor) anchor completion:(AWSCognitoAuthSignOutBlock)completion API_AVAILABLE(ios(13));
Swift
func signOut(withWebUI anchor: ASPresentationAnchor) async throws
-
Sign out locally and from the server.
Declaration
Objective-C
- (void)signOut:(nonnull UIViewController *)vc completion:(nullable AWSCognitoAuthSignOutBlock)completion;
Swift
func signOut(_ vc: UIViewController) async throws
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() async throws
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