FinalizePasskeySignInRequest.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2025 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 Foundation
  17. /// The GCIP endpoint for finalizePasskeySignIn rpc
  18. private let finalizePasskeySignInEndPoint = "accounts/passkeySignIn:finalize"
  19. @available(iOS 15.0, macOS 12.0, tvOS 16.0, *)
  20. class FinalizePasskeySignInRequest: IdentityToolkitRequest, AuthRPCRequest {
  21. typealias Response = FinalizePasskeySignInResponse
  22. /// The credential ID
  23. let credentialID: String
  24. /// The CollectedClientData object from the authenticator.
  25. let clientDataJSON: String
  26. /// The AuthenticatorData from the authenticator.
  27. let authenticatorData: String
  28. /// The signature from the authenticator.
  29. let signature: String
  30. /// The user handle
  31. let userId: String
  32. init(credentialID: String,
  33. clientDataJSON: String,
  34. authenticatorData: String,
  35. signature: String,
  36. userId: String,
  37. requestConfiguration: AuthRequestConfiguration) {
  38. self.credentialID = credentialID
  39. self.clientDataJSON = clientDataJSON
  40. self.authenticatorData = authenticatorData
  41. self.signature = signature
  42. self.userId = userId
  43. super.init(
  44. endpoint: finalizePasskeySignInEndPoint,
  45. requestConfiguration: requestConfiguration,
  46. useIdentityPlatform: true
  47. )
  48. }
  49. var unencodedHTTPRequestBody: [String: AnyHashable]? {
  50. let assertion: [String: AnyHashable] = [
  51. "clientDataJSON": clientDataJSON,
  52. "authenticatorData": authenticatorData,
  53. "signature": signature,
  54. "userHandle": userId,
  55. ]
  56. let authResponse: [String: AnyHashable] = [
  57. "id": credentialID,
  58. "response": assertion,
  59. ]
  60. var postBody: [String: AnyHashable] = [
  61. "authenticatorAuthenticationResponse": authResponse,
  62. ]
  63. if let tenant = tenantID {
  64. postBody["tenantId"] = tenant
  65. }
  66. return postBody
  67. }
  68. }