Skip to content

watchOS support for FirebaseAuth #5585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions FirebaseAuth.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ supports email and password accounts, as well as several 3rd party authenticatio
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.11'
s.tvos.deployment_target = '10.0'
s.watchos.deployment_target = '6.0'

s.cocoapods_version = '>= 1.4.0'
s.static_framework = true
Expand All @@ -46,11 +47,13 @@ supports email and password accounts, as well as several 3rd party authenticatio
s.framework = 'Security'
s.ios.framework = 'SafariServices'
s.dependency 'FirebaseCore', '~> 6.8'
s.dependency 'GoogleUtilities/AppDelegateSwizzler', '~> 6.5'
s.dependency 'GoogleUtilities/Environment', '~> 6.5'
s.dependency 'GoogleUtilities/AppDelegateSwizzler', '~> 6.7'
s.dependency 'GoogleUtilities/Environment', '~> 6.7'
s.dependency 'GTMSessionFetcher/Core', '~> 1.1'

s.test_spec 'unit' do |unit_tests|
# Unit tests can't run on watchOS.
unit_tests.platforms = {:ios => '8.0', :osx => '10.11', :tvos => '10.0'}
unit_tests.source_files = 'FirebaseAuth/Tests/Unit/*.[mh]'
unit_tests.osx.exclude_files = [
'FirebaseAuth/Tests/Unit/FIRAuthAPNSTokenManagerTests.m',
Expand Down
3 changes: 3 additions & 0 deletions FirebaseAuth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be 6.7.0 for sure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline - will leave it as is until it's released.

- [added] Added basic watchOS support. (#4621)

# v6.5.3
- [changed] Remove unused mfa request field "mfa_provider" (#5397)
- [fixed] Suppress deprecation warnings when targeting iOS versions up to iOS 13. (#5437)
Expand Down
45 changes: 21 additions & 24 deletions FirebaseAuth/Sources/Auth/FIRAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#import <GoogleUtilities/GULAppDelegateSwizzler.h>
#import <GoogleUtilities/GULAppEnvironmentUtil.h>
#import <GoogleUtilities/GULSceneDelegateSwizzler.h>
#import <GoogleUtilities/GULSecureCoding.h>
#import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"

#import "FirebaseAuth/Sources/Auth/FIRAuthDataResult_Internal.h"
Expand Down Expand Up @@ -2000,16 +2001,13 @@ - (BOOL)saveUser:(nullable FIRUser *)user error:(NSError *_Nullable *_Nullable)o
if (!user) {
success = [_keychainServices removeDataForKey:userKey error:outError];
} else {
// Encode the user object.
NSMutableData *archiveData = [NSMutableData data];
// iOS 12 deprecation
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSKeyedArchiver *archiver =
[[NSKeyedArchiver alloc] initForWritingWithMutableData:archiveData];
#pragma clang diagnostic pop
[archiver encodeObject:user forKey:userKey];
[archiver finishEncoding];
NSData *archiveData = [GULSecureCoding archivedDataWithObject:user
toKey:userKey
error:outError];
if (outError && *outError) {
// Error archiving the data.
return NO;
}

// Save the user object's encoded value.
success = [_keychainServices setData:archiveData forKey:userKey error:outError];
Expand Down Expand Up @@ -2053,13 +2051,15 @@ - (BOOL)getUser:(FIRUser *_Nullable *)outUser error:(NSError *_Nullable *_Nullab
*outUser = nil;
return YES;
}
// iOS 12 deprecation
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSKeyedUnarchiver *unarchiver =
[[NSKeyedUnarchiver alloc] initForReadingWithData:encodedUserData];
#pragma clang diagnostic pop
FIRUser *user = [unarchiver decodeObjectOfClass:[FIRUser class] forKey:userKey];
FIRUser *user = [GULSecureCoding unarchivedObjectOfClass:[FIRUser class]
fromData:encodedUserData
key:userKey
error:error];
if (error && *error) {
// An error occurred when unarchiving the user, operation failed.
return NO;
}

user.auth = self;
*outUser = user;

Expand Down Expand Up @@ -2225,13 +2225,10 @@ - (nullable FIRUser *)getStoredUserForAccessGroup:(NSString *_Nullable)accessGro
return nil;
}

// iOS 12 deprecation
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSKeyedUnarchiver *unarchiver =
[[NSKeyedUnarchiver alloc] initForReadingWithData:encodedUserData];
#pragma clang diagnostic pop
user = [unarchiver decodeObjectOfClass:[FIRUser class] forKey:userKey];
user = [GULSecureCoding unarchivedObjectOfClass:[FIRUser class]
fromData:encodedUserData
key:userKey
error:outError];
} else {
user = [self.storedUserManager getStoredUserForAccessGroup:self.userAccessGroup
projectIdentifier:self.app.options.APIKey
Expand Down
2 changes: 1 addition & 1 deletion FirebaseAuth/Sources/MultiFactor/FIRMultiFactor+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface FIRMultiFactor ()
@interface FIRMultiFactor () <NSSecureCoding>

@property(nonatomic, weak) FIRUser *user;

Expand Down
7 changes: 4 additions & 3 deletions FirebaseAuth/Sources/Public/FIRAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ NS_SWIFT_NAME(Auth)

- (void)signInWithEmail:(NSString *)email
link:(NSString *)link
completion:(nullable FIRAuthDataResultCallback)completion;
completion:(nullable FIRAuthDataResultCallback)completion API_UNAVAILABLE(watchos);

/** @fn signInWithProvider:UIDelegate:completion:
@brief Signs in using the provided auth provider instance.
Expand Down Expand Up @@ -736,7 +736,8 @@ NS_SWIFT_NAME(Auth)
*/
- (void)sendSignInLinkToEmail:(NSString *)email
actionCodeSettings:(FIRActionCodeSettings *)actionCodeSettings
completion:(nullable FIRSendSignInLinkToEmailCallback)completion;
completion:(nullable FIRSendSignInLinkToEmailCallback)completion
API_UNAVAILABLE(watchos);

/** @fn signOut:
@brief Signs out the current user.
Expand All @@ -762,7 +763,7 @@ NS_SWIFT_NAME(Auth)
@param link The email sign-in link.
@return @YES when the link passed matches the expected format of an email sign-in link.
*/
- (BOOL)isSignInWithEmailLink:(NSString *)link;
- (BOOL)isSignInWithEmailLink:(NSString *)link API_UNAVAILABLE(watchos);

/** @fn addAuthStateDidChangeListener:
@brief Registers a block as an "auth state did change" listener. To be invoked when:
Expand Down
4 changes: 3 additions & 1 deletion FirebaseAuth/Sources/Public/FIRGameCenterAuthProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ typedef void (^FIRGameCenterCredentialCallback)(FIRAuthCredential *_Nullable cre
NS_SWIFT_NAME(GameCenterCredentialCallback);

/** @class FIRGameCenterAuthProvider
@brief A concrete implementation of @c FIRAuthProvider for Game Center Sign In.
@brief A concrete implementation of @c FIRAuthProvider for Game Center Sign In. Not available on
watchOS.
*/
API_UNAVAILABLE(watchos)
NS_SWIFT_NAME(GameCenterAuthProvider)
@interface FIRGameCenterAuthProvider : NSObject

Expand Down
4 changes: 2 additions & 2 deletions FirebaseAuth/Sources/SystemService/FIRAuthAPNSTokenManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include <TargetConditionals.h>
#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_WATCH

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
Expand Down Expand Up @@ -56,7 +56,7 @@ typedef void (^FIRAuthAPNSTokenCallback)(FIRAuthAPNSToken *_Nullable token,
*/
- (instancetype)init NS_UNAVAILABLE;

/** @fn initWithApplication:bundle
/** @fn initWithApplication:
@brief Initializes the instance.
@param application The @c UIApplication to request the token from.
@return The initialized instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include <TargetConditionals.h>
#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_WATCH

#import <GoogleUtilities/GULAppEnvironmentUtil.h>
#import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
Expand Down
28 changes: 17 additions & 11 deletions FirebaseAuth/Sources/SystemService/FIRAuthAppCredentialManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#import "FirebaseAuth/Sources/SystemService/FIRAuthAppCredential.h"
#import "FirebaseAuth/Sources/SystemService/FIRAuthAppCredentialManager.h"

#import <GoogleUtilities/GULSecureCoding.h>

NS_ASSUME_NONNULL_BEGIN

/** @var kKeychainDataKey
Expand Down Expand Up @@ -69,22 +71,26 @@ - (instancetype)initWithKeychain:(FIRAuthKeychainServices *)keychain {
NSError *error;
NSData *encodedData = [_keychainServices dataForKey:kKeychainDataKey error:&error];
if (!error && encodedData) {
// iOS 12 deprecation
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSKeyedUnarchiver *unarchiver =
[[NSKeyedUnarchiver alloc] initForReadingWithData:encodedData];
#pragma clang diagnostic pop
NSError *credentialError;
FIRAuthAppCredential *credential =
[unarchiver decodeObjectOfClass:[FIRAuthAppCredential class] forKey:kFullCredentialKey];
if ([credential isKindOfClass:[FIRAuthAppCredential class]]) {
[GULSecureCoding unarchivedObjectOfClass:[FIRAuthAppCredential class]
fromData:encodedData
key:kFullCredentialKey
error:&credentialError];

if ([credential isKindOfClass:[FIRAuthAppCredential class]] && !credentialError) {
_credential = credential;
}

NSError *receiptsError;
NSSet<Class> *allowedClasses =
[NSSet<Class> setWithObjects:[NSArray class], [NSString class], nil];
NSArray<NSString *> *pendingReceipts = [unarchiver decodeObjectOfClasses:allowedClasses
forKey:kPendingReceiptsKey];
if ([pendingReceipts isKindOfClass:[NSArray class]]) {
NSArray<NSString *> *pendingReceipts =
[GULSecureCoding unarchivedObjectOfClasses:allowedClasses
fromData:encodedData
key:kPendingReceiptsKey
error:&receiptsError];
if ([pendingReceipts isKindOfClass:[NSArray class]] && !receiptsError) {
_pendingReceipts = [pendingReceipts mutableCopy];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include <TargetConditionals.h>
#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_WATCH

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include <TargetConditionals.h>
#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_WATCH

#import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"

Expand Down
8 changes: 4 additions & 4 deletions FirebaseAuth/Sources/SystemService/FIRAuthStoredUserManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
@brief Get the user access group stored locally.
@param outError Return value for any error which occurs.
*/
- (NSString *_Nullable)getStoredUserAccessGroupWithError:(NSError *_Nullable *_Nullable)outError;
- (nullable NSString *)getStoredUserAccessGroupWithError:(NSError *_Nullable *_Nullable)outError;

/** @fn setStoredUserAccessGroup:error:
@brief The setter of the user access group stored locally.
Expand All @@ -66,9 +66,9 @@ NS_ASSUME_NONNULL_BEGIN
we use API KEY.
@param outError Return value for any error which occurs.
*/
- (FIRUser *)getStoredUserForAccessGroup:(NSString *)accessGroup
projectIdentifier:(NSString *)projectIdentifier
error:(NSError *_Nullable *_Nullable)outError;
- (nullable FIRUser *)getStoredUserForAccessGroup:(NSString *)accessGroup
projectIdentifier:(NSString *)projectIdentifier
error:(NSError *_Nullable *_Nullable)outError;

/** @fn setStoredUser:forAccessGroup:projectID:error:
@brief The setter of the user stored locally.
Expand Down
30 changes: 15 additions & 15 deletions FirebaseAuth/Sources/SystemService/FIRAuthStoredUserManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#import "FirebaseAuth/Sources/SystemService/FIRAuthStoredUserManager.h"

#import "FirebaseAuth/Sources/User/FIRUser_Internal.h"

#import <GoogleUtilities/GULSecureCoding.h>

/** @var kUserAccessGroupKey
@brief Key of user access group stored in user defaults. Used for retrieve the user access
group at launch.
Expand Down Expand Up @@ -80,13 +84,15 @@ - (FIRUser *)getStoredUserForAccessGroup:(NSString *)accessGroup
query[(__bridge id)kSecAttrAccount] = kSharedKeychainAccountValue;

NSData *data = [self.keychainServices getItemWithQuery:query error:outError];
// iOS 12 deprecation
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
#pragma clang diagnostic pop
FIRUser *user = [unarchiver decodeObjectOfClass:[FIRUser class] forKey:kStoredUserCoderKey];
// If there's an outError parameter and it's populated, or there's no data, return.
if ((outError && *outError) || !data) {
return nil;
}

FIRUser *user = [GULSecureCoding unarchivedObjectOfClass:[FIRUser class]
fromData:data
key:kStoredUserCoderKey
error:outError];
return user;
}

Expand All @@ -103,15 +109,9 @@ - (BOOL)setStoredUser:(FIRUser *)user
query[(__bridge id)kSecAttrService] = projectIdentifier;
query[(__bridge id)kSecAttrAccount] = kSharedKeychainAccountValue;

NSMutableData *data = [NSMutableData data];
// iOS 12 deprecation
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
#pragma clang diagnostic pop
[archiver encodeObject:user forKey:kStoredUserCoderKey];
[archiver finishEncoding];

NSData *data = [GULSecureCoding archivedDataWithObject:user
toKey:kStoredUserCoderKey
error:outError];
return [self.keychainServices setItem:data withQuery:query error:outError];
}

Expand Down
2 changes: 1 addition & 1 deletion FirebaseAuth/Sources/Utilities/FIRAuthDefaultUIDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include <TargetConditionals.h>
#if !TARGET_OS_OSX
#if !TARGET_OS_OSX && !TARGET_OS_WATCH

#import <GoogleUtilities/GULAppEnvironmentUtil.h>
#import <UIKit/UIKit.h>
Expand Down
2 changes: 1 addition & 1 deletion GoogleUtilities.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GoogleUtilities'
s.version = '6.6.0'
s.version = '6.7.0'
s.summary = 'Google Utilities for iOS (plus community support for macOS and tvOS)'

s.description = <<-DESC
Expand Down
3 changes: 3 additions & 0 deletions GoogleUtilities/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 6.7.0
- Add support for custom keys in archiving and unarchiving with `GULSecureCoding`.

# 6.6.0 -- M69
- Keychain utilities and Keychain based key-value storage added to
`GoogleUtilities/Environment`. (#5329)
Expand Down
Loading