FirebaseAuth Framework Reference (original) (raw)

FIRAuth


@interface FIRAuth : NSObject

Manages authentication for Firebase apps. This class is thread-safe.

Declaration

Objective-C

+ (nonnull FIRAuth *)auth;  

Declaration

Objective-C

+ (nonnull FIRAuth *)authWithApp:(nonnull FIRApp *)app;  

Parameters

app The app for which to retrieve the associated Auth instance.

Return Value

The Auth instance associated with the given app.

Declaration

Objective-C

@property (nonatomic, weak, readonly, nullable) FIRApp *app;  

Declaration

Objective-C

@property (nonatomic, strong, readonly, nullable) FIRUser *currentUser;  

Declaration

Objective-C

@property (nonatomic, copy, nullable) NSString *languageCode;  

Declaration

Objective-C

@property (nonatomic, copy, nullable) FIRAuthSettings *settings;  

Declaration

Objective-C

@property (nonatomic, copy, readonly, nullable) NSString *userAccessGroup;  

Declaration

Objective-C

@property (nonatomic) BOOL shareAuthStateAcrossDevices;  

Declaration

Objective-C

@property (nonatomic, copy, nullable) NSString *tenantID;  

Declaration

Objective-C

@property (nonatomic, strong, nullable) NSData *APNSToken;  

Declaration

Objective-C

@property (nonatomic, copy, nullable) NSString *customAuthDomain;  

Declaration

Objective-C

- (nonnull instancetype)init;  

Declaration

Objective-C

- (void)updateCurrentUser:(nonnull FIRUser *)user  
               completion:(nullable void (^)(NSError *_Nullable))completion;  

Parameters

user The user object to be set as the current user of the calling Auth instance.
completion Optionally; a block invoked after the user of the calling Auth instance has been updated or an error was encountered.
 + `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.  

See AuthErrors for a list of error codes that are common to all API methods.

Declaration

Objective-C

- (void)fetchSignInMethodsForEmail:(nonnull NSString *)email  
                        completion:  
                            (nullable void (^)(NSArray<NSString *> *_Nullable,  
                                               NSError *_Nullable))completion;  

Parameters

email The email address for which to obtain a list of sign-in methods.
completion Optionally; a block which is invoked when the list of sign in methods for the specified email address is ready or an error was encountered. Invoked asynchronously on the main thread in the future.
 + `AuthErrorCodeOperationNotAllowed` - Indicates that email and password  
     accounts are not enabled. Enable them in the Auth section of the  
     Firebase console.  
 + `AuthErrorCodeUserDisabled` - Indicates the user's account is disabled.  
 + `AuthErrorCodeWrongPassword` - Indicates the user attempted  
     sign in with an incorrect password.  
 + `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.  

See AuthErrors for a list of error codes that are common to all API methods.

Declaration

Objective-C

- (void)signInWithEmail:(nonnull NSString *)email  
               password:(nonnull NSString *)password  
             completion:(nullable void (^)(FIRAuthDataResult *_Nullable,  
                                           NSError *_Nullable))completion;  

Parameters

email The user’s email address.
password The user’s password.
completion Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.
+ `AuthErrorCodeOperationNotAllowed` - Indicates that email and email sign-in link  
    accounts are not enabled. Enable them in the Auth section of the  
    Firebase console.  
+ `AuthErrorCodeUserDisabled` - Indicates the user's account is disabled.  
+ `AuthErrorCodeInvalidEmail` - Indicates the email address is invalid.  

See AuthErrors for a list of error codes that are common to all API methods.

Declaration

Objective-C

- (void)signInWithEmail:(nonnull NSString *)email  
                   link:(nonnull NSString *)link  
             completion:(nullable void (^)(FIRAuthDataResult *_Nullable,  
                                           NSError *_Nullable))completion;  

Parameters

email The user’s email address.
link The email sign-in link.
completion Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

Declaration

Parameters

provider An instance of an auth provider used to initiate the sign-in flow.
UIDelegate Optionally an instance of a class conforming to the AuthUIDelegate protocol, this is used for presenting the web context. If nil, a default AuthUIDelegate will be used.
completion Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.

Declaration

Objective-C

- (void)signInWithCredential:(nonnull FIRAuthCredential *)credential  
                  completion:(nullable void (^)(FIRAuthDataResult *_Nullable,  
                                                NSError *_Nullable))completion;  

Parameters

credential The credential supplied by the IdP.
completion Optionally; a block which is invoked when the sign in flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.
+ `AuthErrorCodeOperationNotAllowed` - Indicates that anonymous accounts are  
    not enabled. Enable them in the Auth section of the Firebase console.  

See AuthErrors for a list of error codes that are common to all API methods.

Declaration

Objective-C

- (void)signInAnonymouslyWithCompletion:  
    (nullable void (^)(FIRAuthDataResult *_Nullable,  
                       NSError *_Nullable))completion;  

Parameters

completion Optionally; a block which is invoked when the sign in finishes, or is canceled. Invoked asynchronously on the main thread in the future.
+ `AuthErrorCodeInvalidCustomToken` - Indicates a validation error with  
    the custom token.  
+ `AuthErrorCodeCustomTokenMismatch` - Indicates the service account and the API key  
    belong to different projects.  

See AuthErrors for a list of error codes that are common to all API methods.

Declaration

Objective-C

- (void)signInWithCustomToken:(nonnull NSString *)token  
                   completion:(nullable void (^)(FIRAuthDataResult *_Nullable,  
                                                 NSError *_Nullable))completion;  

Parameters

token A self-signed custom auth token.
completion Optionally; a block which is invoked when the sign in finishes, or is canceled. Invoked asynchronously on the main thread in the future.
+ `AuthErrorCodeInvalidEmail` - Indicates the email address is malformed.  
+ `AuthErrorCodeEmailAlreadyInUse` - Indicates the email used to attempt sign up  
    already exists. Call fetchProvidersForEmail to check which sign-in mechanisms the user  
    used, and prompt the user to sign in with one of those.  
+ `AuthErrorCodeOperationNotAllowed` - Indicates that email and password accounts  
    are not enabled. Enable them in the Auth section of the Firebase console.  
+ `AuthErrorCodeWeakPassword` - Indicates an attempt to set a password that is  
    considered too weak. The NSLocalizedFailureReasonErrorKey field in the NSError.userInfo  
    dictionary object will contain more detailed explanation that can be shown to the user.  

See AuthErrors for a list of error codes that are common to all API methods.

Declaration

Objective-C

- (void)createUserWithEmail:(nonnull NSString *)email  
                   password:(nonnull NSString *)password  
                 completion:(nullable void (^)(FIRAuthDataResult *_Nullable,  
                                               NSError *_Nullable))completion;  

Parameters

email The user’s email address.
password The user’s desired password.
completion Optionally; a block which is invoked when the sign up flow finishes, or is canceled. Invoked asynchronously on the main thread in the future.
+ `AuthErrorCodeWeakPassword` - Indicates an attempt to set a password that is  
    considered too weak.  
+ `AuthErrorCodeOperationNotAllowed` - Indicates the administrator disabled sign  
    in with the specified identity provider.  
+ `AuthErrorCodeExpiredActionCode` - Indicates the OOB code is expired.  
+ `AuthErrorCodeInvalidActionCode` - Indicates the OOB code is invalid.  

See AuthErrors for a list of error codes that are common to all API methods.

Declaration

Objective-C

- (void)confirmPasswordResetWithCode:(nonnull NSString *)code  
                         newPassword:(nonnull NSString *)newPassword  
                          completion:  
                              (nonnull void (^)(NSError *_Nullable))completion;  

Parameters

newPassword The new password.
completion Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.

Declaration

Objective-C

- (void)checkActionCode:(nonnull NSString *)code  
             completion:(nonnull void (^)(FIRActionCodeInfo *_Nullable,  
                                          NSError *_Nullable))completion;  

Parameters

code The out of band code to check validity.
completion Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.

Declaration

Objective-C

- (void)verifyPasswordResetCode:(nonnull NSString *)code  
                     completion:  
                         (nonnull void (^)(NSString *_Nullable,  
                                           NSError *_Nullable))completion;  

Parameters

code The password reset code to be verified.
completion Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.

Declaration

Objective-C

- (void)applyActionCode:(nonnull NSString *)code  
             completion:(nonnull void (^)(NSError *_Nullable))completion;  

Parameters

code The out of band code to be applied.
completion Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.
 + `AuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was  
     sent in the request.  
 + `AuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in  
     the console for this action.  
 + `AuthErrorCodeInvalidMessagePayload` - Indicates an invalid email template for  
     sending update email.  

Declaration

Objective-C

- (void)sendPasswordResetWithEmail:(nonnull NSString *)email  
                        completion:  
                            (nullable void (^)(NSError *_Nullable))completion;  

Parameters

email The email address of the user.
completion Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.
+ `AuthErrorCodeInvalidRecipientEmail` - Indicates an invalid recipient email was  
    sent in the request.  
+ `AuthErrorCodeInvalidSender` - Indicates an invalid sender email is set in  
    the console for this action.  
+ `AuthErrorCodeInvalidMessagePayload` - Indicates an invalid email template for  
    sending update email.  
+ `AuthErrorCodeMissingIosBundleID` - Indicates that the iOS bundle ID is missing when  
    `handleCodeInApp` is set to true.  
+ `AuthErrorCodeMissingAndroidPackageName` - Indicates that the android package name  
    is missing when the `androidInstallApp` flag is set to true.  
+ `AuthErrorCodeUnauthorizedDomain` - Indicates that the domain specified in the  
    continue URL is not allowlisted in the Firebase console.  
+ `AuthErrorCodeInvalidContinueURI` - Indicates that the domain specified in the  
    continue URL is not valid.  

Declaration

Objective-C

- (void)sendPasswordResetWithEmail:(nonnull NSString *)email  
                actionCodeSettings:  
                    (nonnull FIRActionCodeSettings *)actionCodeSettings  
                        completion:  
                            (nullable void (^)(NSError *_Nullable))completion;  

Parameters

email The email address of the user.
actionCodeSettings An ActionCodeSettings object containing settings related to handling action codes.
completion Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.

Declaration

Objective-C

- (void)sendSignInLinkToEmail:(nonnull NSString *)email  
           actionCodeSettings:  
               (nonnull FIRActionCodeSettings *)actionCodeSettings  
                   completion:(nullable void (^)(NSError *_Nullable))completion;  

Parameters

email The email address of the user.
actionCodeSettings An ActionCodeSettings object containing settings related to handling action codes.
completion Optionally; a block which is invoked when the request finishes. Invoked asynchronously on the main thread in the future.
+ `AuthErrorCodeKeychainError` - Indicates an error occurred when accessing the  
    keychain. The `NSLocalizedFailureReasonErrorKey` field in the `userInfo`  
    dictionary will contain more information about the error encountered.  

Declaration

Objective-C

- (BOOL)signOut:(NSError *_Nullable *_Nullable)error;  

Parameters

error Optionally; if an error occurs, upon return contains an NSError object that describes the problem; is nil otherwise.

Return Value

@YES when the sign out request was successful. @NO otherwise.

Declaration

Objective-C

- (BOOL)isSignInWithEmailLink:(nonnull NSString *)link;  

Parameters

link The email sign-in link.

Return Value

Returns true when the link passed matches the expected format of an email sign-in link.

Declaration

Parameters

listener The block to be invoked. The block is always invoked asynchronously on the main thread, even for it’s initial invocation after having been added as a listener.

Return Value

A handle useful for manually unregistering the block as a listener.

Declaration

Parameters

listenerHandle The handle for the listener.

Declaration

Parameters

listener The block to be invoked. The block is always invoked asynchronously on the main thread, even for it’s initial invocation after having been added as a listener.

Return Value

A handle useful for manually unregistering the block as a listener.

Declaration

Parameters

listenerHandle The handle for the listener.

Objective-C

- (void)useAppLanguage;  

Declaration

Objective-C

- (void)useEmulatorWithHost:(nonnull NSString *)host port:(NSInteger)port;  

Declaration

Objective-C

- (BOOL)canHandleURL:(nonnull NSURL *)URL;  

Parameters

URL The URL received by the application delegate from any of the openURL method.

Return Value

Whether or the URL is handled. YES means the URL is for Firebase Auth so the caller should ignore the URL from further processing, and NO means the the URL is for the app (or another library) so the caller should continue handling this URL as usual. If swizzling is disabled, URLs received by the application delegate must be forwarded to this method for phone number auth to work.

Declaration

Declaration

Objective-C

- (BOOL)canHandleNotification:(nonnull NSDictionary *)userInfo;  

Parameters

userInfo A dictionary that contains information related to the notification in question.

Return Value

Whether or the notification is handled. A return value of true means the notification is for Firebase Auth so the caller should ignore the notification from further processing, and false means the notification is for the app (or another library) so the caller should continue handling this notification as usual. If swizzling is disabled, related remote notifications must be forwarded to this method for phone number auth to work.

Declaration

Objective-C

- (void)revokeTokenWithAuthorizationCode:(nonnull NSString *)authorizationCode  
                              completion:(nullable void (^)(NSError *_Nullable))  
                                             completion;  

Parameters

completion (Optional) the block invoked when the request to revoke the token is complete, or fails. Invoked asynchronously on the main thread in the future.

Declaration

Objective-C

- (void)initializeRecaptchaConfigWithCompletion:  
    (nullable void (^)(NSError *_Nullable))completion;  

Declaration

Objective-C

- (BOOL)useUserAccessGroup:(NSString *_Nullable)accessGroup  
                     error:(NSError *_Nullable *_Nullable)outError;  

Declaration

Objective-C

- (nullable FIRUser *)  
    getStoredUserForAccessGroup:(NSString *_Nullable)accessGroup  
                          error:(NSError *_Nullable *_Nullable)outError;