FIRGameCenterAuthCredential.m 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. publicKeyURL:(NSURL *)publicKeyURL
  30. signature:(NSData *)signature
  31. salt:(NSData *)salt
  32. timestamp:(uint64_t)timestamp
  33. displayName:(NSString *)displayName {
  34. self = [super initWithProvider:FIRGameCenterAuthProviderID];
  35. if (self) {
  36. _playerID = [playerID copy];
  37. _publicKeyURL = [publicKeyURL copy];
  38. _signature = [signature copy];
  39. _salt = [salt copy];
  40. _timestamp = timestamp;
  41. _displayName = [displayName copy];
  42. }
  43. return self;
  44. }
  45. - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
  46. [FIRAuthExceptionUtils
  47. raiseMethodNotImplementedExceptionWithReason:
  48. @"Attempt to call prepareVerifyAssertionRequest: on a FIRGameCenterAuthCredential."];
  49. }
  50. #pragma mark - NSSecureCoding
  51. + (BOOL)supportsSecureCoding {
  52. return YES;
  53. }
  54. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  55. NSString *playerID = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"playerID"];
  56. NSURL *publicKeyURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:@"publicKeyURL"];
  57. NSData *signature = [aDecoder decodeObjectOfClass:[NSData class] forKey:@"signature"];
  58. NSData *salt = [aDecoder decodeObjectOfClass:[NSData class] forKey:@"salt"];
  59. NSNumber *timestamp = [aDecoder decodeObjectOfClass:[NSNumber class] forKey:@"timestamp"];
  60. NSString *displayName = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"displayName"];
  61. self = [self initWithPlayerID:playerID
  62. publicKeyURL:publicKeyURL
  63. signature:signature
  64. salt:salt
  65. timestamp:timestamp.unsignedLongLongValue
  66. displayName:displayName];
  67. return self;
  68. }
  69. - (void)encodeWithCoder:(NSCoder *)aCoder {
  70. [aCoder encodeObject:self.playerID forKey:@"playerID"];
  71. [aCoder encodeObject:self.publicKeyURL forKey:@"publicKeyURL"];
  72. [aCoder encodeObject:self.signature forKey:@"signature"];
  73. [aCoder encodeObject:self.salt forKey:@"salt"];
  74. [aCoder encodeObject:[NSNumber numberWithUnsignedLongLong:self.timestamp] forKey:@"timestamp"];
  75. [aCoder encodeObject:self.displayName forKey:@"displayName"];
  76. }
  77. @end
  78. NS_ASSUME_NONNULL_END