FIRFacebookAuthCredential.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/AuthProvider/Facebook/FIRFacebookAuthCredential.h"
  17. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRFacebookAuthProvider.h"
  18. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyAssertionRequest.h"
  19. #import "FirebaseAuth/Sources/Utilities/FIRAuthExceptionUtils.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. @interface FIRFacebookAuthCredential ()
  22. - (nullable instancetype)initWithProvider:(NSString *)provider NS_UNAVAILABLE;
  23. @end
  24. @implementation FIRFacebookAuthCredential {
  25. NSString *_accessToken;
  26. }
  27. - (nullable instancetype)initWithProvider:(NSString *)provider {
  28. [FIRAuthExceptionUtils
  29. raiseMethodNotImplementedExceptionWithReason:@"Please call the designated initializer."];
  30. return nil;
  31. }
  32. - (nullable instancetype)initWithAccessToken:(NSString *)accessToken {
  33. self = [super initWithProvider:FIRFacebookAuthProviderID];
  34. if (self) {
  35. _accessToken = [accessToken copy];
  36. }
  37. return self;
  38. }
  39. - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
  40. request.providerAccessToken = _accessToken;
  41. }
  42. #pragma mark - NSSecureCoding
  43. + (BOOL)supportsSecureCoding {
  44. return YES;
  45. }
  46. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  47. NSString *accessToken = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"accessToken"];
  48. self = [self initWithAccessToken:accessToken];
  49. return self;
  50. }
  51. - (void)encodeWithCoder:(NSCoder *)aCoder {
  52. [aCoder encodeObject:_accessToken forKey:@"accessToken"];
  53. }
  54. @end
  55. NS_ASSUME_NONNULL_END