com.taptap.sdk.login 4.6.2 → 4.7.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Mobile/Editor/NativeDependencies.xml +2 -1
- package/Runtime/Public/TapTapLogin.cs +1 -1
- package/Standalone/Runtime/Internal2/TapLoginClientBridge.cs +87 -0
- package/Standalone/Runtime/Internal2/TapLoginClientBridge.cs.meta +11 -0
- package/Standalone/Runtime/Internal2/TapLoginStandaloneImpl.cs +175 -211
- package/package.json +2 -2
- package/link.xml +0 -4
- package/link.xml.meta +0 -7
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
<androidPackages>
|
|
4
4
|
<repositories>
|
|
5
5
|
<repository>https://repo.maven.apache.org/maven2</repository>
|
|
6
|
+
<repository>https://nexus.xmxdev.com/repository/maven-public</repository>
|
|
6
7
|
</repositories>
|
|
7
|
-
<androidPackage spec="com.taptap.sdk:tap-login-unity:4.
|
|
8
|
+
<androidPackage spec="com.taptap.sdk:tap-login-unity:4.7.0-alpha.14"/>
|
|
8
9
|
</androidPackages>
|
|
9
10
|
<iosPods>
|
|
10
11
|
<sources>
|
|
@@ -7,7 +7,7 @@ namespace TapSDK.Login
|
|
|
7
7
|
public class TapTapLogin
|
|
8
8
|
{
|
|
9
9
|
|
|
10
|
-
public static readonly string Version = "4.
|
|
10
|
+
public static readonly string Version = "4.7.0-alpha.14";
|
|
11
11
|
|
|
12
12
|
public const string TAP_LOGIN_SCOPE_BASIC_INFO = "basic_info";
|
|
13
13
|
public const string TAP_LOGIN_SCOPE_PUBLIC_PROFILE = "public_profile";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
using System.Threading.Tasks;
|
|
2
|
+
using System;
|
|
3
|
+
using TapSDK.Core.Standalone;
|
|
4
|
+
|
|
5
|
+
namespace TapSDK.Login.Internal
|
|
6
|
+
{
|
|
7
|
+
#if UNITY_STANDALONE_WIN
|
|
8
|
+
internal class TapLoginClientBridge
|
|
9
|
+
{
|
|
10
|
+
private static TaskCompletionSource<TapLoginResponseByTapClient> taskCompletionSource;
|
|
11
|
+
|
|
12
|
+
public static async Task<TapLoginResponseByTapClient> LoginWithScopesAsync(string[] scopes, string responseType, string redirectUri,
|
|
13
|
+
string codeChallenge, string state, string codeChallengeMethod, string versonCode, string sdkUa, string info)
|
|
14
|
+
{
|
|
15
|
+
taskCompletionSource = new TaskCompletionSource<TapLoginResponseByTapClient>();
|
|
16
|
+
await Task.Run(() =>
|
|
17
|
+
{
|
|
18
|
+
try
|
|
19
|
+
{
|
|
20
|
+
bool isStartSuccess = TapClientStandalone.StartLoginWithScopes(scopes, responseType, redirectUri, codeChallenge, state, codeChallengeMethod, versonCode, sdkUa, info, LoginDelegate);
|
|
21
|
+
if (!isStartSuccess)
|
|
22
|
+
{
|
|
23
|
+
taskCompletionSource.TrySetResult(new TapLoginResponseByTapClient("发起授权失败,请确认 Tap 客户端是否正常运行"));
|
|
24
|
+
taskCompletionSource = null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (Exception e)
|
|
28
|
+
{
|
|
29
|
+
taskCompletionSource.TrySetResult(new TapLoginResponseByTapClient(false, e.Message));
|
|
30
|
+
taskCompletionSource = null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
return await taskCompletionSource.Task;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private static void LoginDelegate(bool isCancel, string redirectUri)
|
|
38
|
+
{
|
|
39
|
+
if (taskCompletionSource != null)
|
|
40
|
+
{
|
|
41
|
+
taskCompletionSource.TrySetResult(new TapLoginResponseByTapClient(isCancel, redirectUri));
|
|
42
|
+
taskCompletionSource = null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 使用客户端登录结果返回值
|
|
47
|
+
public class TapLoginResponseByTapClient
|
|
48
|
+
{
|
|
49
|
+
|
|
50
|
+
public bool isCancel = false;
|
|
51
|
+
|
|
52
|
+
public string redirectUri;
|
|
53
|
+
|
|
54
|
+
public bool isFail = false;
|
|
55
|
+
|
|
56
|
+
public string errorMsg;
|
|
57
|
+
|
|
58
|
+
public TapLoginResponseByTapClient(bool isCancel, string redirctUri)
|
|
59
|
+
{
|
|
60
|
+
this.redirectUri = redirctUri;
|
|
61
|
+
this.isCancel = isCancel;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public TapLoginResponseByTapClient(string errorMsg)
|
|
65
|
+
{
|
|
66
|
+
isFail = true;
|
|
67
|
+
isCancel = false;
|
|
68
|
+
this.errorMsg = errorMsg;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 使用客户端登录结果回调
|
|
75
|
+
public interface TapLoginCallbackWithTapClient
|
|
76
|
+
{
|
|
77
|
+
void onSuccess(TapLoginResponseByTapClient response);
|
|
78
|
+
|
|
79
|
+
void onFailure(string error);
|
|
80
|
+
|
|
81
|
+
void onCancel();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
#endif
|
|
87
|
+
}
|
|
@@ -80,121 +80,152 @@ namespace TapSDK.Login.Internal
|
|
|
80
80
|
scopes = scopes.Append(complianceScope).ToArray();
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
#if UNITY_STANDALONE_WIN
|
|
83
84
|
// 是否使用 Tap 启动器登录
|
|
84
|
-
bool isNeedLoginByClient =
|
|
85
|
-
|
|
85
|
+
bool isNeedLoginByClient = TapClientStandalone.IsNeedLoginByTapClient();
|
|
86
86
|
if (isNeedLoginByClient)
|
|
87
87
|
{
|
|
88
|
-
|
|
89
|
-
string info = "{\"device_id\":\"" + SystemInfo.deviceModel + "\"}";
|
|
90
|
-
string sdkUA = "client_id=" + TapTapSdk.ClientId + "&uuid=" + SystemInfo.deviceUniqueIdentifier;
|
|
91
|
-
TapLogger.Debug("LoginWithScopes start in mainthread = " + Thread.CurrentThread.ManagedThreadId);
|
|
92
|
-
return Task.Run(async () =>
|
|
88
|
+
async Task<TapTapAccount> innerLogin()
|
|
93
89
|
{
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
TapLogger.Debug("start handle login result");
|
|
104
|
-
TapLogger.Debug("LoginWithScopes handle in mainthread = " + Thread.CurrentThread.ManagedThreadId);
|
|
105
|
-
|
|
106
|
-
if (response.isCancel)
|
|
90
|
+
try
|
|
91
|
+
{
|
|
92
|
+
TapLoginTracker.Instance.TrackStart("loginWithScopes", sessionId, TapLoginTracker.LOGIN_TYPE_CLIENT);
|
|
93
|
+
TapTapAccount account = await AuthorizeInternalWithTapClient<TapTapAccount>(scopes, true);
|
|
94
|
+
IsLogging = false;
|
|
95
|
+
TapLoginTracker.Instance.TrackSuccess("loginWithScopes", sessionId, TapLoginTracker.LOGIN_TYPE_CLIENT);
|
|
96
|
+
return account;
|
|
97
|
+
}
|
|
98
|
+
catch (TaskCanceledException e)
|
|
107
99
|
{
|
|
108
100
|
IsLogging = false;
|
|
109
101
|
TapLoginTracker.Instance.TrackCancel("loginWithScopes", sessionId, TapLoginTracker.LOGIN_TYPE_CLIENT);
|
|
110
|
-
throw
|
|
102
|
+
throw e;
|
|
111
103
|
}
|
|
112
|
-
|
|
104
|
+
catch (Exception e)
|
|
105
|
+
{
|
|
106
|
+
IsLogging = false;
|
|
107
|
+
TapLoginTracker.Instance.TrackFailure("loginWithScopes", sessionId, TapLoginTracker.LOGIN_TYPE_CLIENT, (int)TapErrorCode.ERROR_CODE_UNDEFINED, e.Message ?? "未知错误");
|
|
108
|
+
throw e;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return innerLogin();
|
|
112
|
+
}
|
|
113
|
+
#endif
|
|
114
|
+
/// 非启动器,走扫码或网页流程
|
|
115
|
+
TapLoginTracker.Instance.TrackStart("loginWithScopes", sessionId);
|
|
116
|
+
TaskCompletionSource<TapTapAccount> tcs = new TaskCompletionSource<TapTapAccount>();
|
|
117
|
+
LoginPanelController.OpenParams openParams = new LoginPanelController.OpenParams
|
|
118
|
+
{
|
|
119
|
+
ClientId = TapTapSdk.ClientId,
|
|
120
|
+
Scopes = scopes,
|
|
121
|
+
OnAuth = async (tokenData, loginType) =>
|
|
122
|
+
{
|
|
123
|
+
if (tokenData == null)
|
|
113
124
|
{
|
|
125
|
+
TapLoginTracker.Instance.TrackFailure("loginWithScopes", sessionId, loginType, (int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error");
|
|
114
126
|
IsLogging = false;
|
|
115
|
-
|
|
116
|
-
throw new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, response.errorMsg ?? "未知错误");
|
|
127
|
+
tcs.TrySetException(new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error"));
|
|
117
128
|
}
|
|
118
129
|
else
|
|
119
130
|
{
|
|
120
|
-
|
|
131
|
+
// 将 TokenData 转化为 AccessToken
|
|
132
|
+
AccessToken refreshToken = new AccessToken
|
|
133
|
+
{
|
|
134
|
+
kid = tokenData.Kid,
|
|
135
|
+
tokenType = tokenData.TokenType,
|
|
136
|
+
macKey = tokenData.MacKey,
|
|
137
|
+
macAlgorithm = tokenData.MacAlgorithm,
|
|
138
|
+
scopeSet = tokenData.Scopes
|
|
139
|
+
};
|
|
121
140
|
try
|
|
122
141
|
{
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
string code = queryPairs["code"];
|
|
126
|
-
string uriState = queryPairs["state"];
|
|
127
|
-
string error = queryPairs["error"];
|
|
128
|
-
if (string.IsNullOrEmpty(error) && uriState == state && !string.IsNullOrEmpty(code))
|
|
142
|
+
ProfileData profileData = await LoginService.GetProfile(TapTapSdk.ClientId, refreshToken);
|
|
143
|
+
if (profileData != null)
|
|
129
144
|
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
AccessToken refreshToken = new AccessToken
|
|
137
|
-
{
|
|
138
|
-
kid = tokenData.Kid,
|
|
139
|
-
tokenType = tokenData.TokenType,
|
|
140
|
-
macKey = tokenData.MacKey,
|
|
141
|
-
macAlgorithm = tokenData.MacAlgorithm,
|
|
142
|
-
scopeSet = tokenData.Scopes
|
|
143
|
-
};
|
|
144
|
-
try
|
|
145
|
-
{
|
|
146
|
-
ProfileData profileData = await LoginService.GetProfile(TapTapSdk.ClientId, refreshToken);
|
|
147
|
-
if (profileData != null)
|
|
148
|
-
{
|
|
149
|
-
AccountManager.Instance.Account = new TapTapAccount(
|
|
150
|
-
refreshToken, profileData.OpenId, profileData.UnionId, profileData.Name, profileData.Avatar,
|
|
151
|
-
profileData.Email);
|
|
152
|
-
IsLogging = false;
|
|
153
|
-
TapLoginTracker.Instance.TrackSuccess("loginWithScopes", sessionId, TapLoginTracker.LOGIN_TYPE_CLIENT);
|
|
154
|
-
return AccountManager.Instance.Account;
|
|
155
|
-
}
|
|
156
|
-
else
|
|
157
|
-
{
|
|
158
|
-
throw new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error");
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch (Exception e)
|
|
162
|
-
{
|
|
163
|
-
throw new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error " + e.Message);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
145
|
+
TapLoginTracker.Instance.TrackSuccess("loginWithScopes", sessionId, loginType);
|
|
146
|
+
AccountManager.Instance.Account = new TapTapAccount(
|
|
147
|
+
refreshToken, profileData.OpenId, profileData.UnionId, profileData.Name, profileData.Avatar,
|
|
148
|
+
profileData.Email);
|
|
149
|
+
IsLogging = false;
|
|
150
|
+
tcs.TrySetResult(AccountManager.Instance.Account);
|
|
166
151
|
}
|
|
167
152
|
else
|
|
168
153
|
{
|
|
169
|
-
|
|
170
|
-
|
|
154
|
+
TapLoginTracker.Instance.TrackFailure("loginWithScopes", sessionId, loginType, (int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error");
|
|
155
|
+
IsLogging = false;
|
|
156
|
+
tcs.TrySetException(new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error"));
|
|
171
157
|
}
|
|
172
158
|
}
|
|
173
|
-
catch (Exception
|
|
159
|
+
catch (Exception e)
|
|
174
160
|
{
|
|
161
|
+
TapLoginTracker.Instance.TrackFailure("loginWithScopes", sessionId, loginType, (int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error");
|
|
175
162
|
IsLogging = false;
|
|
176
|
-
|
|
177
|
-
TapLoginTracker.Instance.TrackFailure("loginWithScopes", sessionId, TapLoginTracker.LOGIN_TYPE_CLIENT, (int)TapErrorCode.ERROR_CODE_UNDEFINED, ex.Message ?? "UnKnow Error");
|
|
178
|
-
throw new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, ex.StackTrace);
|
|
163
|
+
tcs.TrySetException(new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error " + e.Message));
|
|
179
164
|
}
|
|
180
165
|
}
|
|
181
|
-
}
|
|
166
|
+
},
|
|
167
|
+
OnError = (e, loginType) =>
|
|
168
|
+
{
|
|
169
|
+
TapLoginTracker.Instance.TrackFailure("loginWithScopes", sessionId, loginType, e.Code, e.Message);
|
|
170
|
+
IsLogging = false;
|
|
171
|
+
tcs.TrySetException(e);
|
|
172
|
+
},
|
|
173
|
+
OnClose = () =>
|
|
174
|
+
{
|
|
175
|
+
TapLoginTracker.Instance.TrackCancel("loginWithScopes", sessionId);
|
|
176
|
+
IsLogging = false;
|
|
177
|
+
tcs.TrySetCanceled();
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
TapSDK.UI.UIManager.Instance.OpenUI<LoginPanelController>("Prefabs/TapLogin/LoginPanel", openParams);
|
|
181
|
+
return tcs.Task;
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
#if UNITY_STANDALONE_WIN
|
|
186
|
+
private async Task<T> AuthorizeInternalWithTapClient<T>(string[] scopes = null, bool needProfile = true)
|
|
187
|
+
{
|
|
188
|
+
string info = "{\"device_id\":\"" + SystemInfo.deviceModel + "\"}";
|
|
189
|
+
string sdkUA = "client_id=" + TapTapSdk.ClientId + "&uuid=" + SystemInfo.deviceUniqueIdentifier;
|
|
190
|
+
TapLogger.Debug("LoginWithScopes start in thread = " + Thread.CurrentThread.ManagedThreadId);
|
|
191
|
+
TaskCompletionSource<T> taskCompletionSource = new TaskCompletionSource<T>();
|
|
192
|
+
|
|
193
|
+
string responseType = "code";
|
|
194
|
+
string redirectUri = "tapoauth://authorize";
|
|
195
|
+
string state = Guid.NewGuid().ToString("N");
|
|
196
|
+
string codeVerifier = CodeUtil.GenerateCodeVerifier();
|
|
197
|
+
string codeChallenge = CodeUtil.GetCodeChallenge(codeVerifier);
|
|
198
|
+
string versionCode = TapTapSDK.Version;
|
|
199
|
+
string codeChallengeMethod = "S256";
|
|
200
|
+
TapLoginClientBridge.TapLoginResponseByTapClient response = await TapLoginClientBridge.LoginWithScopesAsync(scopes,
|
|
201
|
+
responseType, redirectUri, codeChallenge, state, codeChallengeMethod, versionCode, sdkUA, info);
|
|
202
|
+
TapLogger.Debug("start handle login result");
|
|
203
|
+
TapLogger.Debug("LoginWithScopes handle in thread = " + Thread.CurrentThread.ManagedThreadId);
|
|
204
|
+
|
|
205
|
+
if (response.isCancel)
|
|
206
|
+
{
|
|
207
|
+
taskCompletionSource.TrySetException(new TaskCanceledException());
|
|
208
|
+
}
|
|
209
|
+
else if (response.isFail || string.IsNullOrEmpty(response.redirectUri))
|
|
210
|
+
{
|
|
211
|
+
taskCompletionSource.TrySetException(new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, response.errorMsg ?? "未知错误"));
|
|
182
212
|
}
|
|
183
213
|
else
|
|
184
214
|
{
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
LoginPanelController.OpenParams openParams = new LoginPanelController.OpenParams
|
|
215
|
+
TapLogger.Debug("login success prepare get token");
|
|
216
|
+
try
|
|
188
217
|
{
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
218
|
+
Uri uri = new Uri(response.redirectUri);
|
|
219
|
+
NameValueCollection queryPairs = UrlUtils.ParseQueryString(uri.Query);
|
|
220
|
+
string code = queryPairs["code"];
|
|
221
|
+
string uriState = queryPairs["state"];
|
|
222
|
+
string error = queryPairs["error"];
|
|
223
|
+
if (string.IsNullOrEmpty(error) && uriState == state && !string.IsNullOrEmpty(code))
|
|
192
224
|
{
|
|
225
|
+
TokenData tokenData = await LoginService.Authorize(TapTapSdk.ClientId, code, codeVerifier);
|
|
193
226
|
if (tokenData == null)
|
|
194
227
|
{
|
|
195
|
-
|
|
196
|
-
IsLogging = false;
|
|
197
|
-
tcs.TrySetException(new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error"));
|
|
228
|
+
throw new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "get token data failed");
|
|
198
229
|
}
|
|
199
230
|
else
|
|
200
231
|
{
|
|
@@ -207,166 +238,99 @@ namespace TapSDK.Login.Internal
|
|
|
207
238
|
macAlgorithm = tokenData.MacAlgorithm,
|
|
208
239
|
scopeSet = tokenData.Scopes
|
|
209
240
|
};
|
|
210
|
-
|
|
241
|
+
if (!needProfile)
|
|
242
|
+
{
|
|
243
|
+
taskCompletionSource.TrySetResult((T)(object)refreshToken);
|
|
244
|
+
}
|
|
245
|
+
else
|
|
211
246
|
{
|
|
212
247
|
ProfileData profileData = await LoginService.GetProfile(TapTapSdk.ClientId, refreshToken);
|
|
213
248
|
if (profileData != null)
|
|
214
249
|
{
|
|
215
|
-
TapLoginTracker.Instance.TrackSuccess("loginWithScopes", sessionId, loginType);
|
|
216
250
|
AccountManager.Instance.Account = new TapTapAccount(
|
|
217
251
|
refreshToken, profileData.OpenId, profileData.UnionId, profileData.Name, profileData.Avatar,
|
|
218
252
|
profileData.Email);
|
|
219
|
-
|
|
220
|
-
tcs.TrySetResult(AccountManager.Instance.Account);
|
|
253
|
+
taskCompletionSource.TrySetResult((T)(object)AccountManager.Instance.Account);
|
|
221
254
|
}
|
|
222
255
|
else
|
|
223
256
|
{
|
|
224
|
-
|
|
225
|
-
IsLogging = false;
|
|
226
|
-
tcs.TrySetException(new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error"));
|
|
257
|
+
throw new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "fetch profile data failed");
|
|
227
258
|
}
|
|
228
259
|
}
|
|
229
|
-
catch (Exception e)
|
|
230
|
-
{
|
|
231
|
-
TapLoginTracker.Instance.TrackFailure("loginWithScopes", sessionId, loginType, (int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error");
|
|
232
|
-
IsLogging = false;
|
|
233
|
-
tcs.TrySetException(new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error " + e.Message));
|
|
234
|
-
}
|
|
235
260
|
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
{
|
|
239
|
-
TapLoginTracker.Instance.TrackFailure("loginWithScopes", sessionId, loginType, e.Code, e.Message);
|
|
240
|
-
IsLogging = false;
|
|
241
|
-
tcs.TrySetException(e);
|
|
242
|
-
},
|
|
243
|
-
OnClose = () =>
|
|
261
|
+
}
|
|
262
|
+
else
|
|
244
263
|
{
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
tcs.TrySetCanceled();
|
|
264
|
+
TapLogger.Debug("login success prepare get token but get error " + error);
|
|
265
|
+
throw new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, error ?? "数据解析异常");
|
|
248
266
|
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
267
|
+
}
|
|
268
|
+
catch (Exception ex)
|
|
269
|
+
{
|
|
270
|
+
TapLogger.Debug("login success prepare get token fail " + ex.Message);
|
|
271
|
+
taskCompletionSource.TrySetException(ex);
|
|
272
|
+
}
|
|
252
273
|
}
|
|
274
|
+
return await taskCompletionSource.Task;
|
|
253
275
|
}
|
|
276
|
+
#endif
|
|
254
277
|
|
|
255
278
|
public Task<AccessToken> Authorize(string[] scopes = null)
|
|
256
279
|
{
|
|
257
|
-
|
|
258
|
-
|
|
280
|
+
|
|
281
|
+
#if UNITY_STANDALONE_WIN
|
|
282
|
+
// 是否使用 Tap 启动器登录
|
|
283
|
+
bool isNeedLoginByClient = TapClientStandalone.IsNeedLoginByTapClient();
|
|
259
284
|
|
|
260
285
|
if (isNeedLoginByClient)
|
|
261
286
|
{
|
|
262
|
-
|
|
263
|
-
string sdkUA = "client_id=" + TapTapSdk.ClientId + "&uuid=" + SystemInfo.deviceUniqueIdentifier;
|
|
264
|
-
TapLogger.Debug("LoginWithScopes start in mainthread = " + Thread.CurrentThread.ManagedThreadId);
|
|
265
|
-
return Task.Run(async () =>
|
|
287
|
+
async Task<AccessToken> innerLogin()
|
|
266
288
|
{
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
string codeChallengeMethod = "S256";
|
|
274
|
-
TapCoreStandalone.TapLoginResponseByTapClient response = await TapCoreStandalone.LoginWithScopesAsync(scopes,
|
|
275
|
-
responseType, redirectUri, codeChallenge, state, codeChallengeMethod, versionCode, sdkUA, info);
|
|
276
|
-
TapLogger.Debug("start handle login result");
|
|
277
|
-
TapLogger.Debug("LoginWithScopes handle in mainthread = " + Thread.CurrentThread.ManagedThreadId);
|
|
289
|
+
AccessToken token = await AuthorizeInternalWithTapClient<AccessToken>(scopes, false);
|
|
290
|
+
return token;
|
|
291
|
+
}
|
|
292
|
+
return innerLogin();
|
|
293
|
+
}
|
|
294
|
+
#endif
|
|
278
295
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
296
|
+
TaskCompletionSource<AccessToken> tcs = new TaskCompletionSource<AccessToken>();
|
|
297
|
+
LoginPanelController.OpenParams openParams = new LoginPanelController.OpenParams
|
|
298
|
+
{
|
|
299
|
+
ClientId = TapTapSdk.ClientId,
|
|
300
|
+
Scopes = new HashSet<string>(scopes).ToArray(),
|
|
301
|
+
OnAuth = (tokenData, loginType) =>
|
|
302
|
+
{
|
|
303
|
+
if (tokenData == null)
|
|
284
304
|
{
|
|
285
|
-
|
|
305
|
+
tcs.TrySetException(new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error"));
|
|
286
306
|
}
|
|
287
307
|
else
|
|
288
308
|
{
|
|
289
|
-
|
|
290
|
-
|
|
309
|
+
// 将 TokenData 转化为 AccessToken
|
|
310
|
+
AccessToken accessToken = new AccessToken
|
|
291
311
|
{
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
TokenData tokenData = await LoginService.Authorize(TapTapSdk.ClientId, code, codeVerifier);
|
|
300
|
-
if (tokenData == null)
|
|
301
|
-
{
|
|
302
|
-
throw new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, "UnKnow Error");
|
|
303
|
-
}else {
|
|
304
|
-
// 将 TokenData 转化为 AccessToken
|
|
305
|
-
AccessToken refreshToken = new AccessToken
|
|
306
|
-
{
|
|
307
|
-
kid = tokenData.Kid,
|
|
308
|
-
tokenType = tokenData.TokenType,
|
|
309
|
-
macKey = tokenData.MacKey,
|
|
310
|
-
macAlgorithm = tokenData.MacAlgorithm,
|
|
311
|
-
scopeSet = tokenData.Scopes
|
|
312
|
-
};
|
|
313
|
-
return refreshToken;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
else
|
|
317
|
-
{
|
|
318
|
-
TapLogger.Debug("login success prepare get token but get error " + error);
|
|
319
|
-
throw new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, error ?? "数据解析异常");
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
catch (Exception ex)
|
|
323
|
-
{
|
|
324
|
-
TapLogger.Debug("login success prepare get token fail " + ex.StackTrace);
|
|
325
|
-
throw new TapException((int)TapErrorCode.ERROR_CODE_UNDEFINED, ex.StackTrace);
|
|
326
|
-
}
|
|
312
|
+
kid = tokenData.Kid,
|
|
313
|
+
tokenType = tokenData.TokenType,
|
|
314
|
+
macKey = tokenData.MacKey,
|
|
315
|
+
macAlgorithm = tokenData.MacAlgorithm,
|
|
316
|
+
scopeSet = tokenData.Scopes
|
|
317
|
+
};
|
|
318
|
+
tcs.TrySetResult(accessToken);
|
|
327
319
|
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
else
|
|
331
|
-
{
|
|
332
|
-
TaskCompletionSource<AccessToken> tcs = new TaskCompletionSource<AccessToken>();
|
|
333
|
-
LoginPanelController.OpenParams openParams = new LoginPanelController.OpenParams
|
|
320
|
+
},
|
|
321
|
+
OnError = (e, loginType) =>
|
|
334
322
|
{
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
AccessToken accessToken = new AccessToken
|
|
347
|
-
{
|
|
348
|
-
kid = tokenData.Kid,
|
|
349
|
-
tokenType = tokenData.TokenType,
|
|
350
|
-
macKey = tokenData.MacKey,
|
|
351
|
-
macAlgorithm = tokenData.MacAlgorithm,
|
|
352
|
-
scopeSet = tokenData.Scopes
|
|
353
|
-
};
|
|
354
|
-
tcs.TrySetResult(accessToken);
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
OnError = (e, loginType) =>
|
|
358
|
-
{
|
|
359
|
-
tcs.TrySetException(e);
|
|
360
|
-
},
|
|
361
|
-
OnClose = () =>
|
|
362
|
-
{
|
|
363
|
-
tcs.TrySetException(
|
|
364
|
-
new TapException((int)TapErrorCode.ERROR_CODE_LOGIN_CANCEL, "Login Cancel"));
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
TapSDK.UI.UIManager.Instance.OpenUI<LoginPanelController>("Prefabs/TapLogin/LoginPanel", openParams);
|
|
368
|
-
return tcs.Task;
|
|
369
|
-
}
|
|
323
|
+
tcs.TrySetException(e);
|
|
324
|
+
},
|
|
325
|
+
OnClose = () =>
|
|
326
|
+
{
|
|
327
|
+
tcs.TrySetException(
|
|
328
|
+
new TapException((int)TapErrorCode.ERROR_CODE_LOGIN_CANCEL, "Login Cancel"));
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
TapSDK.UI.UIManager.Instance.OpenUI<LoginPanelController>("Prefabs/TapLogin/LoginPanel", openParams);
|
|
332
|
+
return tcs.Task;
|
|
333
|
+
|
|
370
334
|
}
|
|
371
335
|
|
|
372
336
|
public void Logout()
|
package/package.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"name": "com.taptap.sdk.login",
|
|
3
3
|
"displayName": "TapTapSDK Login",
|
|
4
4
|
"description": "TapTapSDK Login",
|
|
5
|
-
"version": "4.
|
|
5
|
+
"version": "4.7.0-alpha.14",
|
|
6
6
|
"unity": "2019.4",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"com.taptap.sdk.core": "4.
|
|
9
|
+
"com.taptap.sdk.core": "4.7.0-alpha.14"
|
|
10
10
|
}
|
|
11
11
|
}
|
package/link.xml
DELETED