FIRFinalizePasskeyEnrollmentRequest.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright 2023 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FirebaseAuth/Sources/Backend/RPC/FIRFinalizePasskeyEnrollmentRequest.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. @var kFinalizePasskeyEnrollmentEndPoint
  20. @brief GCIP endpoint for finalizePasskeyEnrollment rpc
  21. */
  22. static NSString *const kFinalizePasskeyEnrollmentEndPoint = @"accounts/passkeyEnrollment:finalize";
  23. /**
  24. @var kTenantIDKey
  25. @brief The key for the tenant id value in the request.
  26. */
  27. static NSString *const kTenantIDKey = @"tenantId";
  28. /**
  29. @var kIDTokenKey
  30. @brief The key for idToken value in the request.
  31. */
  32. static NSString *const kIDTokenKey = @"idToken";
  33. /**
  34. @var kAuthRegistrationRespKey
  35. @brief The key for registration object from the authenticator.
  36. */
  37. static NSString *const kAuthRegistrationRespKey = @"authenticatorRegistrationResponse";
  38. /**
  39. @var kNameKey
  40. @brief The key of passkey name.
  41. */
  42. static NSString *const kNameKey = @"name";
  43. /**
  44. @var kCredentialIDKey
  45. @brief The key for registered credential identifier.
  46. */
  47. static NSString *const kCredentialIDKey = @"id";
  48. /**
  49. @var kAuthAttestationRespKey
  50. @brief The key for attestation response from a FIDO authenticator.
  51. */
  52. static NSString *const kAuthAttestationRespKey = @"response";
  53. /**
  54. @var kClientDataJsonKey
  55. @brief The key for CollectedClientData object from the authenticator.
  56. */
  57. static NSString *const kClientDataJsonKey = @"clientDataJSON";
  58. /**
  59. @var kAttestationObject
  60. @brief The key for the attestation object from the authenticator.
  61. */
  62. static NSString *const kAttestationObject = @"attestationObject";
  63. @implementation FIRFinalizePasskeyEnrollmentRequest
  64. - (nullable instancetype)initWithIDToken:(NSString *)IDToken
  65. name:(NSString *)name
  66. credentialID:(NSString *)credentialID
  67. clientDataJson:(NSString *)clientDataJson
  68. attestationObject:(NSString *)attestationObject
  69. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  70. self = [super initWithEndpoint:kFinalizePasskeyEnrollmentEndPoint
  71. requestConfiguration:requestConfiguration];
  72. if (self) {
  73. self.useIdentityPlatform = YES;
  74. self.useStaging = NO;
  75. _IDToken = IDToken;
  76. _name = name;
  77. _credentialID = credentialID;
  78. _clientDataJson = clientDataJson;
  79. _attestationObject = attestationObject;
  80. }
  81. return self;
  82. }
  83. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  84. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  85. NSMutableDictionary *authRegistrationResponse = [NSMutableDictionary dictionary];
  86. NSMutableDictionary *authAttestationResponse = [NSMutableDictionary dictionary];
  87. if (_IDToken) {
  88. postBody[kIDTokenKey] = _IDToken;
  89. }
  90. if (_name) {
  91. postBody[kNameKey] = _name;
  92. }
  93. if (_credentialID) {
  94. authRegistrationResponse[kCredentialIDKey] = _credentialID;
  95. }
  96. if (_clientDataJson) {
  97. authAttestationResponse[kClientDataJsonKey] = _clientDataJson;
  98. }
  99. if (_attestationObject) {
  100. authAttestationResponse[kAttestationObject] = _attestationObject;
  101. }
  102. if (self.tenantID) {
  103. postBody[kTenantIDKey] = self.tenantID;
  104. }
  105. authRegistrationResponse[kAuthAttestationRespKey] = authAttestationResponse;
  106. postBody[kAuthRegistrationRespKey] = authRegistrationResponse;
  107. return [postBody copy];
  108. }
  109. @end
  110. NS_ASSUME_NONNULL_END