-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
1. implemented rpc call to startPasskeyEnrollment 2. defined startPasskeyEnrollment request and response 3. added unit tests
- Loading branch information
1 parent
0e7e4f9
commit b8f0972
Showing
8 changed files
with
709 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeyEnrollmentRequest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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 "FirebaseAuth/Sources/Backend/FIRAuthRPCRequest.h" | ||
#import "FirebaseAuth/Sources/Backend/FIRIdentityToolkitRequest.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** @class FIRStartPasskeyEnrollmentRequest | ||
@brief Represents the parameters for the startPasskeyEnrollment endpoint. | ||
*/ | ||
@interface FIRStartPasskeyEnrollmentRequest : FIRIdentityToolkitRequest <FIRAuthRPCRequest> | ||
|
||
/** | ||
@property IDToken | ||
@brief The raw user access token | ||
*/ | ||
@property(nonatomic, copy, readonly) NSString *IDToken; | ||
|
||
- (nullable instancetype)initWithIDToken:(NSString *)IDToken | ||
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
67 changes: 67 additions & 0 deletions
67
FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeyEnrollmentRequest.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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 "FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeyEnrollmentRequest.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
@var kStartPasskeyEnrollmentEndPoint | ||
@brief GCIP endpoint for startPasskeyEnrollment rpc | ||
*/ | ||
static NSString *const kStartPasskeyEnrollmentEndPoint = @"accounts/passkeyEnrollment:start"; | ||
|
||
/** | ||
@var kTenantIDKey | ||
@brief The key for the tenant id value in the request. | ||
*/ | ||
static NSString *const kTenantIDKey = @"tenantId"; | ||
|
||
/** | ||
@var kIDToken | ||
@brief The key for idToken value in the request. | ||
*/ | ||
static NSString *const kIDToken = @"idToken"; | ||
|
||
@implementation FIRStartPasskeyEnrollmentRequest | ||
|
||
- (nullable instancetype)initWithIDToken:(NSString *)IDToken | ||
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration { | ||
self = [super initWithEndpoint:kStartPasskeyEnrollmentEndPoint | ||
requestConfiguration:requestConfiguration]; | ||
|
||
if (self) { | ||
_IDToken = IDToken; | ||
self.useIdentityPlatform = YES; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error { | ||
NSMutableDictionary *postBody = [NSMutableDictionary dictionary]; | ||
if (_IDToken) { | ||
postBody[kIDToken] = _IDToken; | ||
} | ||
if (self.tenantID) { | ||
postBody[kTenantIDKey] = self.tenantID; | ||
} | ||
return [postBody copy]; | ||
} | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
47 changes: 47 additions & 0 deletions
47
FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeyEnrollmentResponse.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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 "FirebaseAuth/Sources/Backend/FIRAuthRPCResponse.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
@class FIRStartPasskeyEnrollmentResponse | ||
@brief Represents the response from the startPasskeyEnrollment endpoint. | ||
*/ | ||
@interface FIRStartPasskeyEnrollmentResponse : NSObject <FIRAuthRPCResponse> | ||
|
||
/** | ||
@property rpID | ||
@brief The RP ID of the FIDO Relying Party. | ||
*/ | ||
@property(nonatomic, readonly, copy) NSString *rpID; | ||
|
||
/** | ||
@property userID | ||
@brief The user ID. | ||
*/ | ||
@property(nonatomic, readonly, copy) NSString *userID; | ||
|
||
/** | ||
@property challenge | ||
@brief The FIDO challenge. | ||
*/ | ||
@property(nonatomic, readonly, copy) NSString *challenge; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
75 changes: 75 additions & 0 deletions
75
FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeyEnrollmentResponse.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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 "FirebaseAuth/Sources/Backend/RPC/FIRStartPasskeyEnrollmentResponse.h" | ||
|
||
/** | ||
@var kOptionsKey | ||
@brief The name of the field in the response JSON for CredentialCreationOptions. | ||
*/ | ||
static const NSString *kOptionsKey = @"credentialCreationOptions"; | ||
|
||
/** | ||
@var kRpKey | ||
@brief The name of the field in the response JSON for Relying Party. | ||
*/ | ||
static const NSString *kRpKey = @"rp"; | ||
|
||
/** | ||
@var kUserKey | ||
@brief The name of the field in the response JSON for User. | ||
*/ | ||
static const NSString *kUserKey = @"user"; | ||
|
||
/** | ||
@var kIDKey | ||
@brief The name of the field in the response JSON for ids. | ||
*/ | ||
static const NSString *kIDKey = @"id"; | ||
|
||
/** | ||
@var kChallengeKey | ||
@brief The name of the field in the response JSON for challenge. | ||
*/ | ||
static const NSString *kChallengeKey = @"challenge"; | ||
|
||
@implementation FIRStartPasskeyEnrollmentResponse | ||
|
||
- (BOOL)setWithDictionary:(nonnull NSDictionary *)dictionary | ||
error:(NSError *__autoreleasing _Nullable *_Nullable)error { | ||
if (dictionary[kOptionsKey] == nil) { | ||
return NO; | ||
} | ||
if (dictionary[kOptionsKey][kRpKey] == nil || dictionary[kOptionsKey][kRpKey][kIDKey] == nil) { | ||
return NO; | ||
} | ||
|
||
if (dictionary[kOptionsKey][kUserKey] == nil || | ||
dictionary[kOptionsKey][kUserKey][kIDKey] == nil) { | ||
return NO; | ||
} | ||
|
||
if (dictionary[kOptionsKey][kChallengeKey] == nil) { | ||
return NO; | ||
} | ||
|
||
_rpID = dictionary[kOptionsKey][kRpKey][kIDKey]; | ||
_userID = dictionary[kOptionsKey][kUserKey][kIDKey]; | ||
_challenge = dictionary[kOptionsKey][kChallengeKey]; | ||
return YES; | ||
} | ||
|
||
@end |
Oops, something went wrong.