FIRGameCenterAuthCredential.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2018 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/GameCenter/FIRGameCenterAuthCredential.h"
  17. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRGameCenterAuthProvider.h"
  18. #import "FirebaseAuth/Sources/AuthProvider/FIRAuthCredential_Internal.h"
  19. #import "FirebaseAuth/Sources/Backend/RPC/FIRVerifyAssertionRequest.h"
  20. #import "FirebaseAuth/Sources/Utilities/FIRAuthExceptionUtils.h"
  21. NS_ASSUME_NONNULL_BEGIN
  22. @implementation FIRGameCenterAuthCredential
  23. - (nullable instancetype)initWithProvider:(NSString *)provider {
  24. [FIRAuthExceptionUtils
  25. raiseMethodNotImplementedExceptionWithReason:@"Please call the designated initializer."];
  26. return nil;
  27. }
  28. - (nullable instancetype)initWithPlayerID:(NSString *)playerID
  29. teamPlayerID:(nullable NSString *)teamPlayerID
  30. gamePlayerID:(nullable NSString *)gamePlayerID
  31. publicKeyURL:(NSURL *)publicKeyURL
  32. signature:(NSData *)signature
  33. salt:(NSData *)salt
  34. timestamp:(uint64_t)timestamp
  35. displayName:(NSString *)displayName {
  36. self = [super initWithProvider:FIRGameCenterAuthProviderID];
  37. if (self) {
  38. _playerID = [playerID copy];
  39. _teamPlayerID = [teamPlayerID copy];
  40. _gamePlayerID = [gamePlayerID copy];
  41. _publicKeyURL = [publicKeyURL copy];
  42. _signature = [signature copy];
  43. _salt = [salt copy];
  44. _timestamp = timestamp;
  45. _displayName = [displayName copy];
  46. }
  47. return self;
  48. }
  49. - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
  50. [FIRAuthExceptionUtils
  51. raiseMethodNotImplementedExceptionWithReason:
  52. @"Attempt to call prepareVerifyAssertionRequest: on a FIRGameCenterAuthCredential."];
  53. }
  54. #pragma mark - NSSecureCoding
  55. + (BOOL)supportsSecureCoding {
  56. return YES;
  57. }
  58. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  59. NSString *playerID = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"playerID"];
  60. NSString *teamPlayerID = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"teamPlayerID"];
  61. NSString *gamePlayerID = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"gamePlayerID"];
  62. NSURL *publicKeyURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:@"publicKeyURL"];
  63. NSData *signature = [aDecoder decodeObjectOfClass:[NSData class] forKey:@"signature"];
  64. NSData *salt = [aDecoder decodeObjectOfClass:[NSData class] forKey:@"salt"];
  65. NSNumber *timestamp = [aDecoder decodeObjectOfClass:[NSNumber class] forKey:@"timestamp"];
  66. NSString *displayName = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"displayName"];
  67. self = [self initWithPlayerID:playerID
  68. teamPlayerID:teamPlayerID
  69. gamePlayerID:gamePlayerID
  70. publicKeyURL:publicKeyURL
  71. signature:signature
  72. salt:salt
  73. timestamp:timestamp.unsignedLongLongValue
  74. displayName:displayName];
  75. return self;
  76. }
  77. - (void)encodeWithCoder:(NSCoder *)aCoder {
  78. [aCoder encodeObject:self.playerID forKey:@"playerID"];
  79. [aCoder encodeObject:self.teamPlayerID forKey:@"teamPlayerID"];
  80. [aCoder encodeObject:self.gamePlayerID forKey:@"gamePlayerID"];
  81. [aCoder encodeObject:self.publicKeyURL forKey:@"publicKeyURL"];
  82. [aCoder encodeObject:self.signature forKey:@"signature"];
  83. [aCoder encodeObject:self.salt forKey:@"salt"];
  84. [aCoder encodeObject:[NSNumber numberWithUnsignedLongLong:self.timestamp] forKey:@"timestamp"];
  85. [aCoder encodeObject:self.displayName forKey:@"displayName"];
  86. }
  87. @end
  88. NS_ASSUME_NONNULL_END