You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.7 KiB

6 years ago
6 years ago
6 years ago
  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 "FIREmailPasswordAuthCredential.h"
  17. #import "FIREmailAuthProvider.h"
  18. #import "FIRAuthExceptionUtils.h"
  19. #import "FIRVerifyAssertionRequest.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. @interface FIREmailPasswordAuthCredential ()
  22. - (nullable instancetype)initWithProvider:(NSString *)provider NS_UNAVAILABLE;
  23. @end
  24. @implementation FIREmailPasswordAuthCredential
  25. - (nullable instancetype)initWithProvider:(NSString *)provider {
  26. [FIRAuthExceptionUtils raiseMethodNotImplementedExceptionWithReason:
  27. @"Please call the designated initializer."];
  28. return nil;
  29. }
  30. - (nullable instancetype)initWithEmail:(NSString *)email password:(NSString *)password {
  31. self = [super initWithProvider:FIREmailAuthProviderID];
  32. if (self) {
  33. _email = [email copy];
  34. _password = [password copy];
  35. }
  36. return self;
  37. }
  38. - (nullable instancetype)initWithEmail:(NSString *)email link:(NSString *)link {
  39. self = [super initWithProvider:FIREmailAuthProviderID];
  40. if (self) {
  41. _email = [email copy];
  42. _link = [link copy];
  43. }
  44. return self;
  45. }
  46. - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
  47. [FIRAuthExceptionUtils raiseMethodNotImplementedExceptionWithReason:
  48. @"Attempt to call prepareVerifyAssertionRequest: on a FIREmailPasswordAuthCredential."];
  49. }
  50. #pragma mark - NSSecureCoding
  51. + (BOOL)supportsSecureCoding {
  52. return YES;
  53. }
  54. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  55. NSString *email = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"email"];
  56. NSString *password = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"password"];
  57. NSString *link = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"link"];
  58. if (email.length && password.length) {
  59. self = [self initWithEmail:email password:password];
  60. } else if (email.length && link.length) {
  61. self = [self initWithEmail:email link:link];
  62. } else {
  63. self = nil;
  64. }
  65. return self;
  66. }
  67. - (void)encodeWithCoder:(NSCoder *)aCoder {
  68. [aCoder encodeObject:self.email forKey:@"email"];
  69. [aCoder encodeObject:self.password forKey:@"password"];
  70. [aCoder encodeObject:self.link forKey:@"link"];
  71. }
  72. @end
  73. NS_ASSUME_NONNULL_END