You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.5 KiB

  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 "FIRSignInWithGameCenterRequest.h"
  17. #import "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. publicKeyURL:(NSURL *)publicKeyURL
  26. signature:(NSData *)signature
  27. salt:(NSData *)salt
  28. timestamp:(uint64_t)timestamp
  29. displayName:(NSString *)displayName
  30. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  31. self = [super initWithEndpoint:kSignInWithGameCenterEndPoint
  32. requestConfiguration:requestConfiguration];
  33. if (self) {
  34. _playerID = playerID;
  35. _publicKeyURL = [publicKeyURL copy];
  36. _signature = [signature copy];
  37. _salt = [salt copy];
  38. _timestamp = timestamp;
  39. _displayName = displayName;
  40. }
  41. return self;
  42. }
  43. #pragma mark - FIRAuthRPCRequest
  44. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  45. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  46. if (_playerID) {
  47. postBody[@"playerId"] = _playerID;
  48. }
  49. if (_publicKeyURL) {
  50. postBody[@"publicKeyUrl"] = _publicKeyURL.absoluteString;
  51. }
  52. if (_signature) {
  53. postBody[@"signature"] = [_signature fir_base64URLEncodedStringWithOptions:0];
  54. }
  55. if (_salt) {
  56. postBody[@"salt"] = [_salt fir_base64URLEncodedStringWithOptions:0];
  57. }
  58. if (_timestamp != 0) {
  59. postBody[@"timestamp"] = [NSNumber numberWithUnsignedLongLong:_timestamp];
  60. }
  61. if (_accessToken) {
  62. postBody[@"idToken"] = _accessToken;
  63. }
  64. if (_displayName) {
  65. postBody[@"displayName"] = _displayName;
  66. }
  67. return postBody;
  68. }
  69. @end
  70. NS_ASSUME_NONNULL_END