IOSTokenClient.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // <copyright file="IOSTokenClient.cs" company="Google Inc.">
  2. // Copyright (C) 2015 Google Inc.
  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. // </copyright>
  16. #if (UNITY_IPHONE && !NO_GPGS)
  17. namespace GooglePlayGames.IOS {
  18. using System;
  19. using System.Linq;
  20. using GooglePlayGames.BasicApi;
  21. using GooglePlayGames.Native; // Token retrieval
  22. using GooglePlayGames.Native.PInvoke;
  23. using GooglePlayGames.OurUtils;
  24. using System.Runtime.InteropServices;
  25. using System.Reflection;
  26. using System.Collections.Generic;
  27. using UnityEngine;
  28. using C = GooglePlayGames.Native.Cwrapper.InternalHooks;
  29. internal class IOSTokenClient: TokenClient
  30. {
  31. [System.Runtime.InteropServices.DllImport("__Internal")]
  32. private static extern string _GooglePlayGetIdToken();
  33. [System.Runtime.InteropServices.DllImport("__Internal")]
  34. private static extern string _GooglePlayGetAccessToken();
  35. [System.Runtime.InteropServices.DllImport("__Internal")]
  36. private static extern string _GooglePlayGetUserEmail();
  37. /// <summary>
  38. /// Sets the rationale. Not used for ios.
  39. /// </summary>
  40. /// <param name="rationale">Rationale.</param>
  41. public void SetRationale(string rationale)
  42. {
  43. // not used for iOS.
  44. }
  45. /// <summary>
  46. /// Gets the user's email.
  47. /// </summary>
  48. /// <remarks>The email address returned is selected by the user from the accounts present
  49. /// on the device. There is no guarantee this uniquely identifies the player.
  50. /// For unique identification use the id property of the local player.
  51. /// The user can also choose to not select any email address, meaning it is not
  52. /// available.</remarks>
  53. /// <returns>The user email or null if not authenticated or the permission is
  54. /// not available.</returns>
  55. public string GetEmail()
  56. {
  57. return _GooglePlayGetUserEmail();
  58. }
  59. /// <summary>
  60. /// Gets the user's email with a callback.
  61. /// </summary>
  62. /// <remarks>The email address returned is selected by the user from the accounts present
  63. /// on the device. There is no guarantee this uniquely identifies the player.
  64. /// For unique identification use the id property of the local player.
  65. /// The user can also choose to not select any email address, meaning it is not
  66. /// available.</remarks>
  67. /// <param name="callback">The callback with a status code of the request,
  68. /// and string which is the email. It can be null.</param>
  69. public void GetEmail(Action<CommonStatusCodes, string> callback)
  70. {
  71. string email = GetEmail();
  72. CommonStatusCodes status =
  73. string.IsNullOrEmpty(email) ? CommonStatusCodes.Error : CommonStatusCodes.Success;
  74. if (callback != null) {
  75. callback(status, email);
  76. }
  77. }
  78. /// <summary>Gets the access token currently associated with the Unity activity.</summary>
  79. /// <returns>The OAuth 2.0 access token.</returns>
  80. public string GetAccessToken()
  81. {
  82. return _GooglePlayGetAccessToken();
  83. }
  84. /// <summary>
  85. /// Gets the OpenID Connect ID token for authentication with a server backend.
  86. /// </summary>
  87. /// <param name="idTokenCallback"> A callback to be invoked after token is retrieved. Will be passed null value
  88. /// on failure. </param>
  89. /// <param name="serverClientID">Server client ID from console.developers.google.com or the Play Games
  90. /// services console.</param>
  91. public void GetIdToken(string serverClientID, Action<string> idTokenCallback)
  92. {
  93. var token = _GooglePlayGetIdToken();
  94. if(String.IsNullOrEmpty(token))
  95. {
  96. idTokenCallback(null);
  97. }
  98. else
  99. {
  100. idTokenCallback(token);
  101. }
  102. }
  103. public string GetAuthCode()
  104. {
  105. throw new NotImplementedException();
  106. }
  107. public void GetAnotherServerAuthCode(bool reAuthenticateIfNeeded,
  108. Action<string> callback)
  109. {
  110. throw new NotImplementedException();
  111. }
  112. public string GetIdToken()
  113. {
  114. throw new NotImplementedException();
  115. }
  116. public void Signout()
  117. {
  118. throw new NotImplementedException();
  119. }
  120. public void SetRequestAuthCode(bool flag, bool forceRefresh)
  121. {
  122. throw new NotImplementedException();
  123. }
  124. public void SetRequestEmail(bool flag)
  125. {
  126. throw new NotImplementedException();
  127. }
  128. public void SetRequestIdToken(bool flag)
  129. {
  130. throw new NotImplementedException();
  131. }
  132. public void SetWebClientId(string webClientId)
  133. {
  134. throw new NotImplementedException();
  135. }
  136. public void SetAccountName(string accountName)
  137. {
  138. throw new NotImplementedException();
  139. }
  140. public void AddOauthScopes(string[] scopes)
  141. {
  142. throw new NotImplementedException();
  143. }
  144. public void SetHidePopups(bool flag)
  145. {
  146. throw new NotImplementedException();
  147. }
  148. public bool NeedsToRun()
  149. {
  150. throw new NotImplementedException();
  151. }
  152. public void FetchTokens(Action callback)
  153. {
  154. throw new NotImplementedException();
  155. }
  156. public void FetchTokens(Action<int> callback) {
  157. throw new NotImplementedException();
  158. }
  159. }
  160. }
  161. #endif