FIRFinalizePasskeySignInRequest.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/FIRFinalizePasskeySignInRequest.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. @var kFinalizePasskeySignInEndPoint
  20. @brief GCIP endpoint for finalizePasskeySignIn rpc
  21. */
  22. static NSString *const kFinalizePasskeySignInEndPoint = @"accounts/passkeySignIn: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 kAuthenticatorAuthRespKey
  30. @brief The key for authentication response object from the authenticator.
  31. */
  32. static NSString *const kAuthenticatorAuthRespKey = @"authenticatorAuthenticationResponse";
  33. /**
  34. @var kCredentialIDKey
  35. @brief The key for registered credential identifier.
  36. */
  37. static NSString *const kCredentialIDKey = @"id";
  38. /**
  39. @var kAuthAssertionRespKey
  40. @brief The key for authentication assertion from the authenticator.
  41. */
  42. static NSString *const kAuthAssertionRespKey = @"response";
  43. /**
  44. @var kClientDataJsonKey
  45. @brief The key for CollectedClientData object from the authenticator.
  46. */
  47. static NSString *const kClientDataJsonKey = @"clientDataJSON";
  48. /**
  49. @var kAuthenticatorDataKey
  50. @brief The key for authenticatorData from the authenticator.
  51. */
  52. static NSString *const kAuthenticatorDataKey = @"authenticatorData";
  53. /**
  54. @var kSignatureKey
  55. @brief The key for the signature from the authenticator.
  56. */
  57. static NSString *const kSignatureKey = @"signature";
  58. /**
  59. @var kUserHandleKey
  60. @brief The key for the user handle. This is the same as user ID.
  61. */
  62. static NSString *const kUserHandleKey = @"userHandle";
  63. @implementation FIRFinalizePasskeySignInRequest
  64. - (nullable instancetype)initWithCredentialID:(NSString *)credentialID
  65. clientDataJson:(NSString *)clientDataJson
  66. authenticatorData:(NSString *)authenticatorData
  67. signature:(NSString *)signature
  68. userID:(NSString *)userID
  69. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  70. self = [super initWithEndpoint:kFinalizePasskeySignInEndPoint
  71. requestConfiguration:requestConfiguration];
  72. if (self) {
  73. self.useIdentityPlatform = YES;
  74. self.useStaging = NO;
  75. _credentialID = credentialID;
  76. _clientDataJson = clientDataJson;
  77. _authenticatorData = authenticatorData;
  78. _signature = signature;
  79. _userID = userID;
  80. }
  81. return self;
  82. }
  83. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  84. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  85. NSMutableDictionary *authenticatorAuthResponse = [NSMutableDictionary dictionary];
  86. NSMutableDictionary *authAssertionResponse = [NSMutableDictionary dictionary];
  87. if (self.tenantID) {
  88. postBody[kTenantIDKey] = self.tenantID;
  89. }
  90. if (_credentialID) {
  91. authenticatorAuthResponse[kCredentialIDKey] = _credentialID;
  92. }
  93. if (_clientDataJson) {
  94. authAssertionResponse[kClientDataJsonKey] = _clientDataJson;
  95. }
  96. if (_authenticatorData) {
  97. authAssertionResponse[kAuthenticatorDataKey] = _authenticatorData;
  98. }
  99. if (_signature) {
  100. authAssertionResponse[kSignatureKey] = _signature;
  101. }
  102. if (_userID) {
  103. authAssertionResponse[kUserHandleKey] = _userID;
  104. }
  105. authenticatorAuthResponse[kAuthAssertionRespKey] = authAssertionResponse;
  106. postBody[kAuthenticatorAuthRespKey] = authenticatorAuthResponse;
  107. return [postBody copy];
  108. }
  109. @end
  110. NS_ASSUME_NONNULL_END