Skip to content
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

public changes for passkey support #11546

Draft
wants to merge 13 commits into
base: passkey-main
Choose a base branch
from
18 changes: 18 additions & 0 deletions FirebaseAuth/Sources/Auth/FIRAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
#import "FirebaseAuth/Sources/Utilities/FIRAuthURLPresenter.h"
#endif

#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX || TARGET_OS_MACCATALYST
@class ASAuthorizationPlatformPublicKeyCredentialAssertion;
@class ASAuthorizationPlatformPublicKeyCredentialAssertionRequest;
#endif

NS_ASSUME_NONNULL_BEGIN

#pragma mark-- Logger Service String.
Expand Down Expand Up @@ -2369,6 +2374,19 @@ - (nullable FIRUser *)getStoredUserForAccessGroup:(NSString *_Nullable)accessGro
return user;
}

- (void)startPasskeySignInWithCompletion:
(nullable void (^)(
ASAuthorizationPlatformPublicKeyCredentialAssertionRequest *_Nullable request,
NSError *_Nullable error))completion {
}

- (void)finalizePasskeySignInWithPlatformCredential:
(ASAuthorizationPlatformPublicKeyCredentialAssertion *)platformCredential
completion:(nullable void (^)(
FIRAuthDataResult *_Nullable result,
NSError *_Nullable error))completion {
}

@end

NS_ASSUME_NONNULL_END
23 changes: 23 additions & 0 deletions FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,29 @@ NS_SWIFT_NAME(Auth)
error:(NSError *_Nullable *_Nullable)outError
__attribute__((swift_error(nonnull_error))); // This method can return `nil` on success.

#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX || TARGET_OS_MACCATALYST
/**
@fn startPasskeySignInWithCompletion
@brief create key assertion request for sign in
*/
- (void)startPasskeySignInWithCompletion:
(nullable void (^)(
ASAuthorizationPlatformPublicKeyCredentialAssertionRequest *_Nullable request,
NSError *_Nullable error))completion API_AVAILABLE(macos(12.0), ios(15.0), tvos(16.0));

/**
@fn finalizePasskeySignInWithPlatformCredential:completion
@brief sign in with passkey credential
*/
- (void)finalizePasskeySignInWithPlatformCredential:
(ASAuthorizationPlatformPublicKeyCredentialAssertion *)platformCredential
completion:(nullable void (^)(
FIRAuthDataResult *_Nullable authResult,
NSError *_Nullable error))completion
NS_SWIFT_NAME(finalizePasskeySignIn(with:completion:))
API_AVAILABLE(macos(12.0), ios(15.0), tvos(16.0));

#endif
@end

NS_ASSUME_NONNULL_END
39 changes: 39 additions & 0 deletions FirebaseAuth/Sources/Public/FirebaseAuth/FIRPasskeyInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
@class FIRPasskey
@brief Passkey Info
*/
NS_SWIFT_NAME(PasskeyInfo) API_UNAVAILABLE(watchos) @interface FIRPasskeyInfo : NSObject

/**
@brief Passkey name
*/
@property(nonatomic, readonly) NSString *name;

/**
@brief Passkey credential ID
*/
@property(nonatomic, readonly) NSString *credentialID;

@end

NS_ASSUME_NONNULL_END
43 changes: 43 additions & 0 deletions FirebaseAuth/Sources/Public/FirebaseAuth/FIRUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#import "FIRAuth.h"
#import "FIRAuthDataResult.h"
#import "FIRMultiFactor.h"
#import "FIRPasskeyInfo.h"
#import "FIRUserInfo.h"

@class FIRAuthTokenResult;
Expand Down Expand Up @@ -123,6 +124,11 @@ NS_SWIFT_NAME(User)
@property(nonatomic, readonly, nonnull)
FIRMultiFactor *multiFactor API_UNAVAILABLE(macos, tvos, watchos);

/** @property enrolledPasskeys
@brief a list of user enrolled passkey object.
*/
@property(nonatomic, readonly) NSArray<FIRPasskeyInfo *> *enrolledPasskeys API_UNAVAILABLE(watchos);

/** @fn init
@brief This class should not be instantiated.
@remarks To retrieve the current user, use `Auth.currentUser`. To sign a user
Expand Down Expand Up @@ -506,6 +512,43 @@ NS_SWIFT_NAME(User)
completion:
(nullable void (^)(NSError *_Nullable error))completion;

#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX || TARGET_OS_MACCATALYST
/**
@fn startPasskeyEnrollmentWithName:completion
@brief Create an registration request for enroll.
*/
- (void)startPasskeyEnrollmentWithName:(nullable NSString *)name
completion:
(nullable void (^)(
ASAuthorizationPlatformPublicKeyCredentialRegistrationRequest
*_Nullable request,
NSError *_Nullable error))completion
NS_SWIFT_NAME(startPasskeyEnrollment(with:completion:))
API_AVAILABLE(macos(12.0), ios(15.0), tvos(16.0));

/**
@fn finalizePasskeyEnrollmentWithPlatformCredential:completion
@brief Register the platform credential with GCIP for current user.
@param platformCredential the credential generated by keyChain.
*/
- (void)finalizePasskeyEnrollmentWithPlatformCredential:
(ASAuthorizationPlatformPublicKeyCredentialRegistration *)platformCredential
completion:(nullable void (^)(
FIRAuthDataResult *_Nullable authResult,
NSError *_Nullable error))completion
NS_SWIFT_NAME(finalizePasskeyEnrollment(with:completion:))
API_AVAILABLE(macos(12.0), ios(15.0), tvos(16.0));

#endif
/**
@fn unenrollPasskeyWithCredentialID:completion
@brief To unenroll a passkey with platform credential.
@param credentialID the passkey credential ID to unenroll.
*/
- (void)unenrollPasskeyWithCredentialID:(NSString *)credentialID
completion:(nullable void (^)(NSError *_Nullable error))completion
NS_SWIFT_NAME(unenrollPasskey(with:completion:));

@end

/** @class FIRUserProfileChangeRequest
Expand Down
1 change: 1 addition & 0 deletions FirebaseAuth/Sources/Public/FirebaseAuth/FirebaseAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#import "FIRAuthAPNSTokenType.h"
#import "FIRAuthSettings.h"
#import "FIRAuthUIDelegate.h"
#import "FIRPasskeyInfo.h"
#import "FIRPhoneAuthCredential.h"
#import "FIRPhoneAuthProvider.h"
#import "FIRPhoneMultiFactorAssertion.h"
Expand Down
27 changes: 27 additions & 0 deletions FirebaseAuth/Sources/User/FIRUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
#import "FirebaseAuth/Sources/AuthProvider/Phone/FIRPhoneAuthCredential_Internal.h"
#endif

#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX || TARGET_OS_MACCATALYST
@class ASAuthorizationPlatformPublicKeyCredentialRegistration;
@class ASAuthorizationPlatformPublicKeyCredentialRegistrationRequest;
#endif

NS_ASSUME_NONNULL_BEGIN

/** @var kUserIDCodingKey
Expand Down Expand Up @@ -1517,6 +1522,28 @@ - (void)signOutIfTokenIsInvalidWithError:(nullable NSError *)error {
}
}

#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX || TARGET_OS_MACCATALYST
- (void)finalizePasskeyEnrollmentWithPlatformCredential:
(nonnull ASAuthorizationPlatformPublicKeyCredentialRegistration *)platformCredential
completion:(nullable void (^)(
FIRAuthDataResult *_Nullable result,
NSError *_Nullable error))completion {
}

- (void)startPasskeyEnrollmentWithName:(nullable NSString *)name
completion:
(nullable void (^)(
ASAuthorizationPlatformPublicKeyCredentialRegistrationRequest
*_Nullable request,
NSError *_Nullable error))completion {
}

#endif

- (void)unenrollPasskeyWithCredentialID:(nonnull NSString *)credentialID
completion:(nullable void (^)(NSError *_Nullable error))completion {
}

@end

@implementation FIRUserProfileChangeRequest {
Expand Down
Loading