FIRStartPasskeyEnrollmentResponse.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/FIRStartPasskeyEnrollmentResponse.h"
  17. /**
  18. @var kOptionsKey
  19. @brief The name of the field in the response JSON for CredentialCreationOptions.
  20. */
  21. static const NSString *kOptionsKey = @"credentialCreationOptions";
  22. /**
  23. @var kRpKey
  24. @brief The name of the field in the response JSON for Relying Party.
  25. */
  26. static const NSString *kRpKey = @"rp";
  27. /**
  28. @var kUserKey
  29. @brief The name of the field in the response JSON for User.
  30. */
  31. static const NSString *kUserKey = @"user";
  32. /**
  33. @var kIDKey
  34. @brief The name of the field in the response JSON for ids.
  35. */
  36. static const NSString *kIDKey = @"id";
  37. /**
  38. @var kChallengeKey
  39. @brief The name of the field in the response JSON for challenge.
  40. */
  41. static const NSString *kChallengeKey = @"challenge";
  42. @implementation FIRStartPasskeyEnrollmentResponse
  43. - (BOOL)setWithDictionary:(nonnull NSDictionary *)dictionary
  44. error:(NSError *__autoreleasing _Nullable *_Nullable)error {
  45. if (dictionary[kOptionsKey] == nil) {
  46. return NO;
  47. }
  48. if (dictionary[kOptionsKey][kRpKey] == nil || dictionary[kOptionsKey][kRpKey][kIDKey] == nil) {
  49. return NO;
  50. }
  51. if (dictionary[kOptionsKey][kUserKey] == nil ||
  52. dictionary[kOptionsKey][kUserKey][kIDKey] == nil) {
  53. return NO;
  54. }
  55. if (dictionary[kOptionsKey][kChallengeKey] == nil) {
  56. return NO;
  57. }
  58. _rpID = dictionary[kOptionsKey][kRpKey][kIDKey];
  59. _userID = dictionary[kOptionsKey][kUserKey][kIDKey];
  60. _challenge = dictionary[kOptionsKey][kChallengeKey];
  61. return YES;
  62. }
  63. @end