FIRSignInWithGameCenterRequest.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/Backend/RPC/FIRSignInWithGameCenterRequest.h"
  17. #import "FirebaseAuth/Sources/Utilities/NSData+FIRBase64.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** @var kSignInWithGameCenterEndPoint
  20. @brief The "SignInWithGameCenter" endpoint.
  21. */
  22. static NSString *const kSignInWithGameCenterEndPoint = @"signInWithGameCenter";
  23. @implementation FIRSignInWithGameCenterRequest
  24. - (nullable instancetype)initWithPlayerID:(NSString *)playerID
  25. teamPlayerID:(nullable NSString *)teamPlayerID
  26. gamePlayerID:(nullable NSString *)gamePlayerID
  27. publicKeyURL:(NSURL *)publicKeyURL
  28. signature:(NSData *)signature
  29. salt:(NSData *)salt
  30. timestamp:(uint64_t)timestamp
  31. displayName:(NSString *)displayName
  32. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  33. self = [super initWithEndpoint:kSignInWithGameCenterEndPoint
  34. requestConfiguration:requestConfiguration];
  35. if (self) {
  36. _playerID = playerID;
  37. _teamPlayerID = [teamPlayerID copy];
  38. _gamePlayerID = [gamePlayerID copy];
  39. _publicKeyURL = [publicKeyURL copy];
  40. _signature = [signature copy];
  41. _salt = [salt copy];
  42. _timestamp = timestamp;
  43. _displayName = displayName;
  44. }
  45. return self;
  46. }
  47. #pragma mark - FIRAuthRPCRequest
  48. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  49. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  50. if (_playerID) {
  51. postBody[@"playerId"] = _playerID;
  52. }
  53. if (_teamPlayerID) {
  54. postBody[@"teamPlayerId"] = _teamPlayerID;
  55. }
  56. if (_gamePlayerID) {
  57. postBody[@"gamePlayerId"] = _gamePlayerID;
  58. }
  59. if (_publicKeyURL) {
  60. postBody[@"publicKeyUrl"] = _publicKeyURL.absoluteString;
  61. }
  62. if (_signature) {
  63. postBody[@"signature"] = [_signature fir_base64URLEncodedStringWithOptions:0];
  64. }
  65. if (_salt) {
  66. postBody[@"salt"] = [_salt fir_base64URLEncodedStringWithOptions:0];
  67. }
  68. if (_timestamp != 0) {
  69. postBody[@"timestamp"] = [NSNumber numberWithUnsignedLongLong:_timestamp];
  70. }
  71. if (_accessToken) {
  72. postBody[@"idToken"] = _accessToken;
  73. }
  74. if (_displayName) {
  75. postBody[@"displayName"] = _displayName;
  76. }
  77. return [postBody copy];
  78. }
  79. @end
  80. NS_ASSUME_NONNULL_END