FIREmailLinkSignInRequest.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2017 Google
  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/LICENSE-2.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/FIREmailLinkSignInRequest.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /** @var kEmailLinkSigninEndpoint
  19. @brief The "EmailLinkSignin" endpoint.
  20. */
  21. static NSString *const kEmailLinkSigninEndpoint = @"emailLinkSignin";
  22. /** @var kEmailKey
  23. @brief The key for the "identifier" value in the request.
  24. */
  25. static NSString *const kEmailKey = @"email";
  26. /** @var kEmailLinkKey
  27. @brief The key for the "emailLink" value in the request.
  28. */
  29. static NSString *const kOOBCodeKey = @"oobCode";
  30. /** @var kIDTokenKey
  31. @brief The key for the "IDToken" value in the request.
  32. */
  33. static NSString *const kIDTokenKey = @"idToken";
  34. /** @var kPostBodyKey
  35. @brief The key for the "postBody" value in the request.
  36. */
  37. static NSString *const kPostBodyKey = @"postBody";
  38. /** @var kTenantIDKey
  39. @brief The key for the tenant id value in the request.
  40. */
  41. static NSString *const kTenantIDKey = @"tenantId";
  42. @implementation FIREmailLinkSignInRequest
  43. - (instancetype)initWithEmail:(NSString *)email
  44. oobCode:(NSString *)oobCode
  45. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  46. self = [super initWithEndpoint:kEmailLinkSigninEndpoint
  47. requestConfiguration:requestConfiguration];
  48. if (self) {
  49. _email = email;
  50. _oobCode = oobCode;
  51. }
  52. return self;
  53. }
  54. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  55. NSMutableDictionary *postBody = [@{
  56. kEmailKey : _email,
  57. kOOBCodeKey : _oobCode,
  58. } mutableCopy];
  59. if (_IDToken) {
  60. postBody[kIDTokenKey] = _IDToken;
  61. }
  62. if (self.tenantID) {
  63. postBody[kTenantIDKey] = self.tenantID;
  64. }
  65. return [postBody copy];
  66. }
  67. @end
  68. NS_ASSUME_NONNULL_END