No Description

FIROAuthCredential.m 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 "FIROAuthCredential.h"
  17. #import "FIRAuthCredential_Internal.h"
  18. #import "FIRAuthExceptionUtils.h"
  19. #import "FIROAuthCredential_Internal.h"
  20. #import "FIRVerifyAssertionRequest.h"
  21. #import "FIRVerifyAssertionResponse.h"
  22. NS_ASSUME_NONNULL_BEGIN
  23. @interface FIROAuthCredential ()
  24. @property(nonatomic, nullable) NSString *rawNonce;
  25. - (nullable instancetype)initWithProvider:(NSString *)provider NS_UNAVAILABLE;
  26. @end
  27. @implementation FIROAuthCredential
  28. - (nullable instancetype)initWithProvider:(NSString *)provider {
  29. [FIRAuthExceptionUtils raiseMethodNotImplementedExceptionWithReason:
  30. @"Please call the designated initializer."];
  31. return nil;
  32. }
  33. - (instancetype)initWithProviderID:(NSString *)providerID
  34. IDToken:(nullable NSString *)IDToken
  35. rawNonce:(nullable NSString *)rawNonce
  36. accessToken:(nullable NSString *)accessToken
  37. secret:(nullable NSString *)secret
  38. pendingToken:(nullable NSString *)pendingToken {
  39. self = [super initWithProvider:providerID];
  40. if (self) {
  41. _IDToken = IDToken;
  42. _rawNonce = rawNonce;
  43. _accessToken = accessToken;
  44. _pendingToken = pendingToken;
  45. _secret = secret;
  46. }
  47. return self;
  48. }
  49. - (instancetype)initWithProviderID:(NSString *)providerID
  50. sessionID:(NSString *)sessionID
  51. OAuthResponseURLString:(NSString *)OAuthResponseURLString {
  52. self = [self initWithProviderID:providerID
  53. IDToken:nil
  54. rawNonce:nil
  55. accessToken:nil
  56. secret:nil
  57. pendingToken:nil];
  58. if (self) {
  59. _OAuthResponseURLString = OAuthResponseURLString;
  60. _sessionID = sessionID;
  61. }
  62. return self;
  63. }
  64. - (nullable instancetype)initWithVerifyAssertionResponse:(FIRVerifyAssertionResponse *)response {
  65. if (response.oauthIDToken.length || response.oauthAccessToken.length ||
  66. response.oauthSecretToken.length) {
  67. return [self initWithProviderID:response.providerID
  68. IDToken:response.oauthIDToken
  69. rawNonce:nil
  70. accessToken:response.oauthAccessToken
  71. secret:response.oauthSecretToken
  72. pendingToken:response.pendingToken];
  73. }
  74. return nil;
  75. }
  76. - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
  77. request.providerIDToken = _IDToken;
  78. request.providerRawNonce = _rawNonce;
  79. request.providerAccessToken = _accessToken;
  80. request.requestURI = _OAuthResponseURLString;
  81. request.sessionID = _sessionID;
  82. request.providerOAuthTokenSecret = _secret;
  83. request.pendingToken = _pendingToken;
  84. }
  85. #pragma mark - NSSecureCoding
  86. + (BOOL)supportsSecureCoding {
  87. return YES;
  88. }
  89. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  90. NSString *IDToken = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"IDToken"];
  91. NSString *rawNonce = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"rawNonce"];
  92. NSString *accessToken = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"accessToken"];
  93. NSString *pendingToken = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"pendingToken"];
  94. NSString *secret = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"secret"];
  95. self = [self initWithProviderID:self.provider
  96. IDToken:IDToken
  97. rawNonce:rawNonce
  98. accessToken:accessToken
  99. secret:secret
  100. pendingToken:pendingToken];
  101. return self;
  102. }
  103. - (void)encodeWithCoder:(NSCoder *)aCoder {
  104. [aCoder encodeObject:self.IDToken forKey:@"IDToken"];
  105. [aCoder encodeObject:self.rawNonce forKey:@"rawNonce"];
  106. [aCoder encodeObject:self.accessToken forKey:@"accessToken"];
  107. [aCoder encodeObject:self.pendingToken forKey:@"pendingToken"];
  108. [aCoder encodeObject:self.secret forKey:@"secret"];
  109. }
  110. @end
  111. NS_ASSUME_NONNULL_END