com.taptap.sdk.login 4.8.4-beta.1 → 4.8.4-beta.2

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.
@@ -1,128 +1,128 @@
1
- using System;
2
- using System.Net;
3
- using UnityEngine;
4
- using UnityEngine.UI;
5
- using TapSDK.Login.Internal.Http;
6
- using System.Collections.Specialized;
7
- using TapSDK.Core.Internal.Utils;
8
- using TapSDK.Core.Internal.Log;
9
- using TapSDK.Login.Standalone.Internal;
10
-
11
- namespace TapSDK.Login.Internal {
12
- public class WebController {
13
- private readonly Action<TokenData, String> onAuth;
14
-
15
- private readonly Text titleText;
16
- private readonly Button jumpButton;
17
- private readonly Text descriptionText;
18
-
19
- private HttpListener server;
20
-
21
- private string clientId;
22
-
23
- protected string[] scopes;
24
-
25
- private bool isRunning;
26
-
27
- public WebController(Transform transform, Action<TokenData, String> onAuth) {
28
- this.onAuth = onAuth;
29
-
30
- titleText = transform.Find("Title").GetComponent<Text>();
31
- jumpButton = transform.Find("JumpButton").GetComponent<Button>();
32
- descriptionText = transform.Find("Description").GetComponent<Text>();
33
-
34
- jumpButton.onClick.AddListener(OnJumpClicked);
35
- }
36
-
37
- protected void LoadBasicInfo(string clientId) {
38
- this.clientId = clientId;
39
-
40
- ILoginLang lang = LoginLanguage.GetCurrentLang();
41
- titleText.text = lang.WebLogin();
42
- Text jumpText = jumpButton.transform.Find("Text").GetComponent<Text>();
43
- jumpText.text = lang.WebButtonJumpToWeb();
44
- descriptionText.text = lang.WebNotice();
45
- }
46
-
47
- public void Load(string clientId, string[] scopes) {
48
- LoadBasicInfo(clientId);
49
- this.scopes = scopes;
50
- }
51
-
52
- public void Unload() {
53
- isRunning = false;
54
- server?.Stop();
55
- }
56
-
57
- protected virtual async void OnJumpClicked() {
58
- ILoginLang lang = LoginLanguage.GetCurrentLang();
59
- UI.UIManager.Instance.OpenToast(true,
60
- lang.WebNoticeLogin(),
61
- icon: UI.UIManager.WhiteToastInfoIcon);
62
-
63
- WebLoginRequestManager.Instance.CreateNewLoginRequest(scopes);
64
-
65
- string url = WebLoginRequestManager.Instance.GetCurrentRequest().GetWebLoginUrl();
66
- TapLog.Log("WebController , OpenURL : " + url);
67
- Application.OpenURL(url);
68
-
69
- // 启动监听
70
- server = new HttpListener();
71
- server.Prefixes.Add(WebLoginRequestManager.Instance.GetCurrentRequest().GetRedirectHost());
72
- server.Start();
73
-
74
- isRunning = true;
75
- while (isRunning) {
76
- try {
77
- HttpListenerContext context = await server.GetContextAsync();
78
- TapLog.Log($"{context.Request.HttpMethod} {context.Request.Url}");
79
- context.Response.StatusCode = 200;
80
- context.Response.Close();
81
-
82
- if (context.Request.HttpMethod == "OPTIONS") {
83
- continue;
84
- }
85
-
86
- // 检测 url 合法性
87
- string code = GetRequestCode(context.Request.Url);
88
- // 判断授权失败
89
- if (string.IsNullOrEmpty(code)) {
90
- // 授权失败
91
- UI.UIManager.Instance.OpenToast(true,
92
- $"{lang.WebNoticeFail()},{lang.WebNoticeFail2()}",
93
- icon: UI.UIManager.WhiteToastErrorIcon);
94
- continue;
95
- }
96
-
97
- TokenData tokenData = await LoginService.Authorize(clientId, code);
98
- TapLog.Log("Login , WebController Success");
99
- onAuth.Invoke(tokenData, TapLoginTracker.LOGIN_TYPE_BROWSER);
100
-
101
- return;
102
- } catch (Exception) {
103
- continue;
104
- }
105
- }
106
- }
107
-
108
- private string GetRequestCode(Uri uri) {
109
- if (uri == null) {
110
- return null;
111
- }
112
-
113
- if (!uri.LocalPath.Contains(CodeUtil.GetTapTapOAuthPrefix())) {
114
- return null;
115
- }
116
-
117
- NameValueCollection queryPairs = UrlUtils.ParseQueryString(uri.Query);
118
- string code = queryPairs["code"];
119
- string state = queryPairs["state"];
120
- if (string.IsNullOrEmpty(state) || string.IsNullOrEmpty(code)) {
121
- return null;
122
- }
123
-
124
- return state.Equals(WebLoginRequestManager.Instance.GetCurrentRequest().GetState()) ?
125
- code : null;
126
- }
127
- }
128
- }
1
+ using System;
2
+ using System.Net;
3
+ using UnityEngine;
4
+ using UnityEngine.UI;
5
+ using TapSDK.Login.Internal.Http;
6
+ using System.Collections.Specialized;
7
+ using TapSDK.Core.Internal.Utils;
8
+ using TapSDK.Core.Internal.Log;
9
+ using TapSDK.Login.Standalone.Internal;
10
+
11
+ namespace TapSDK.Login.Internal {
12
+ public class WebController {
13
+ private readonly Action<TokenData, String> onAuth;
14
+
15
+ private readonly Text titleText;
16
+ private readonly Button jumpButton;
17
+ private readonly Text descriptionText;
18
+
19
+ private HttpListener server;
20
+
21
+ private string clientId;
22
+
23
+ protected string[] scopes;
24
+
25
+ private bool isRunning;
26
+
27
+ public WebController(Transform transform, Action<TokenData, String> onAuth) {
28
+ this.onAuth = onAuth;
29
+
30
+ titleText = transform.Find("Title").GetComponent<Text>();
31
+ jumpButton = transform.Find("JumpButton").GetComponent<Button>();
32
+ descriptionText = transform.Find("Description").GetComponent<Text>();
33
+
34
+ jumpButton.onClick.AddListener(OnJumpClicked);
35
+ }
36
+
37
+ protected void LoadBasicInfo(string clientId) {
38
+ this.clientId = clientId;
39
+
40
+ ILoginLang lang = LoginLanguage.GetCurrentLang();
41
+ titleText.text = lang.WebLogin();
42
+ Text jumpText = jumpButton.transform.Find("Text").GetComponent<Text>();
43
+ jumpText.text = lang.WebButtonJumpToWeb();
44
+ descriptionText.text = lang.WebNotice();
45
+ }
46
+
47
+ public void Load(string clientId, string[] scopes) {
48
+ LoadBasicInfo(clientId);
49
+ this.scopes = scopes;
50
+ }
51
+
52
+ public void Unload() {
53
+ isRunning = false;
54
+ server?.Stop();
55
+ }
56
+
57
+ protected virtual async void OnJumpClicked() {
58
+ ILoginLang lang = LoginLanguage.GetCurrentLang();
59
+ UI.UIManager.Instance.OpenToast(true,
60
+ lang.WebNoticeLogin(),
61
+ icon: UI.UIManager.WhiteToastInfoIcon);
62
+
63
+ WebLoginRequestManager.Instance.CreateNewLoginRequest(scopes);
64
+
65
+ string url = WebLoginRequestManager.Instance.GetCurrentRequest().GetWebLoginUrl();
66
+ TapLog.Log("WebController , OpenURL : " + url);
67
+ Application.OpenURL(url);
68
+
69
+ // 启动监听
70
+ server = new HttpListener();
71
+ server.Prefixes.Add(WebLoginRequestManager.Instance.GetCurrentRequest().GetRedirectHost());
72
+ server.Start();
73
+
74
+ isRunning = true;
75
+ while (isRunning) {
76
+ try {
77
+ HttpListenerContext context = await server.GetContextAsync();
78
+ TapLog.Log($"{context.Request.HttpMethod} {context.Request.Url}");
79
+ context.Response.StatusCode = 200;
80
+ context.Response.Close();
81
+
82
+ if (context.Request.HttpMethod == "OPTIONS") {
83
+ continue;
84
+ }
85
+
86
+ // 检测 url 合法性
87
+ string code = GetRequestCode(context.Request.Url);
88
+ // 判断授权失败
89
+ if (string.IsNullOrEmpty(code)) {
90
+ // 授权失败
91
+ UI.UIManager.Instance.OpenToast(true,
92
+ $"{lang.WebNoticeFail()},{lang.WebNoticeFail2()}",
93
+ icon: UI.UIManager.WhiteToastErrorIcon);
94
+ continue;
95
+ }
96
+
97
+ TokenData tokenData = await LoginService.Authorize(clientId, code);
98
+ TapLog.Log("Login , WebController Success");
99
+ onAuth.Invoke(tokenData, TapLoginTracker.LOGIN_TYPE_BROWSER);
100
+
101
+ return;
102
+ } catch (Exception) {
103
+ continue;
104
+ }
105
+ }
106
+ }
107
+
108
+ private string GetRequestCode(Uri uri) {
109
+ if (uri == null) {
110
+ return null;
111
+ }
112
+
113
+ if (!uri.LocalPath.Contains(CodeUtil.GetTapTapOAuthPrefix())) {
114
+ return null;
115
+ }
116
+
117
+ NameValueCollection queryPairs = UrlUtils.ParseQueryString(uri.Query);
118
+ string code = queryPairs["code"];
119
+ string state = queryPairs["state"];
120
+ if (string.IsNullOrEmpty(state) || string.IsNullOrEmpty(code)) {
121
+ return null;
122
+ }
123
+
124
+ return state.Equals(WebLoginRequestManager.Instance.GetCurrentRequest().GetState()) ?
125
+ code : null;
126
+ }
127
+ }
128
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
- "name": "com.taptap.sdk.login",
3
- "displayName": "TapTapSDK Login",
4
- "description": "TapTapSDK Login",
5
- "version": "4.8.4-beta.1",
6
- "unity": "2019.4",
7
- "license": "MIT",
8
- "dependencies": {
9
- "com.taptap.sdk.core": "4.8.4-beta.1"
10
- }
2
+ "name": "com.taptap.sdk.login",
3
+ "displayName": "TapTapSDK Login",
4
+ "description": "TapTapSDK Login",
5
+ "version": "4.8.4-beta.2",
6
+ "unity": "2020.3.0f1",
7
+ "license": "MIT",
8
+ "dependencies": {
9
+ "com.taptap.sdk.core": "4.8.4-beta.2"
10
+ }
11
11
  }