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
23 changes: 23 additions & 0 deletions FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#import <AvailabilityMacros.h>
#import <Foundation/Foundation.h>

#import <AuthenticationServices/AuthenticationServices.h>
Copy link
Member

Choose a reason for hiding this comment

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

@paulb777, should types from this framework instead be forward declared within the header?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, and wrapped in #if TARGET_OS_IOS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you elaborate on the forward declaration part?

another question on TARGET_OS_IOS, these APIs will run on mac os, ios and tv os (but not watch OS).
I was thinking using
if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MAC. However going thru this doc, I have the assumption that TARGET_OS_MAC will include all IOS, TVOS and WATCHOS, can you suggest?

Copy link
Member

Choose a reason for hiding this comment

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

can you elaborate on the forward declaration part?

So line 20 should be moved to the implementation file. And in its place should be forward declarations for the types used from the AuthenticationServices module. The diff should look like:

Suggested change
#import <AuthenticationServices/AuthenticationServices.h>
@class ASAuthorizationPlatformPublicKeyCredentialAssertion;
@class ASAuthorizationPlatformPublicKeyCredentialAssertionRequest;

another question on TARGET_OS_IOS, these APIs will run on mac os, ios and tv os (but not watch OS).
I was thinking using
if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_MAC. However going thru this doc, I have the assumption that TARGET_OS_MAC will include all IOS, TVOS and WATCHOS, can you suggest?

TARGET_OS_MAC might be too broad. Something like the following should specifically get all platforms except watchOS:

#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_OSX || TARGET_OS_MACCATALYST

#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you Nick. After trying the suggestion we synced offline, it seems importing in the .m file still cause me compiler errors. Can you help me take a look where I might did wrong? (CI is also failing for the same issue)

#import "FIRAuthAPNSTokenType.h"
#import "FIRAuthErrors.h"

Expand Down Expand Up @@ -877,6 +878,28 @@ 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
/**
@fn finalizePasskeySignInWithPlatformCredential:completion
@brief sign in with passkey credential
*/
- (void)finalizePasskeySignInWithPlatformCredential:
(ASAuthorizationPlatformPublicKeyCredentialAssertion *)platformCredential
completion:(nullable void (^)(
FIRAuthDataResult *_Nullable authResult,
NSError *_Nullable error))completion
API_AVAILABLE(ios(15.0));

/**
@fn startPasskeySignInWithCompletion
@brief create key assertion request for sign in
*/
- (void)startPasskeySignInWithCompletion:
(nullable void (^)(
ASAuthorizationPlatformPublicKeyCredentialAssertionRequest *_Nullable request,
NSError *_Nullable error))completion API_AVAILABLE(ios(15.0));

#endif
@end

NS_ASSUME_NONNULL_END
39 changes: 39 additions & 0 deletions FirebaseAuth/Sources/Public/FirebaseAuth/FIRPasskey.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(Passkey) API_UNAVAILABLE(macos, tvos, watchos) @interface FIRPasskey : NSObject

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

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

@end

NS_ASSUME_NONNULL_END
41 changes: 41 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 "FIRPasskey.h"
#import "FIRUserInfo.h"

@class FIRAuthTokenResult;
Expand Down Expand Up @@ -123,6 +124,13 @@ 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.
This property is available on iOS only.
*/
@property(nonatomic, readonly)
NSArray<FIRPasskey *> *enrolledPasskeys API_UNAVAILABLE(macos, tvos, 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 +514,39 @@ NS_SWIFT_NAME(User)
completion:
(nullable void (^)(NSError *_Nullable error))completion;

#if TARGET_OS_IOS
/**
@fn startPasskeyEnrollmentWithCompletion
@brief Create an registration request for enroll.
*/
- (void)startPasskeyEnrollmentWithCompletion:
(nullable void (^)(
ASAuthorizationPlatformPublicKeyCredentialRegistrationRequest *_Nullable request,
NSError *_Nullable error))completion API_AVAILABLE(ios(15.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
API_AVAILABLE(ios(15.0));

/**
@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
API_AVAILABLE(ios(15.0));

#endif

@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 "FIRPasskey.h"
#import "FIRPhoneAuthCredential.h"
#import "FIRPhoneAuthProvider.h"
#import "FIRPhoneMultiFactorAssertion.h"
Expand Down
Loading