capacitor-sso-webview 0.0.6 → 0.0.7
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.
|
@@ -25,6 +25,7 @@ public class SSOWebView {
|
|
|
25
25
|
private Dialog dialog;
|
|
26
26
|
private WebView webView;
|
|
27
27
|
private boolean alreadyRedirected = false;
|
|
28
|
+
private boolean bodyRead = false;
|
|
28
29
|
|
|
29
30
|
public void open(
|
|
30
31
|
final Activity activity,
|
|
@@ -34,6 +35,7 @@ public class SSOWebView {
|
|
|
34
35
|
final String title,
|
|
35
36
|
final Listener listener) {
|
|
36
37
|
alreadyRedirected = false;
|
|
38
|
+
bodyRead = false;
|
|
37
39
|
|
|
38
40
|
dialog = new Dialog(activity, android.R.style.Theme_Light_NoTitleBar_Fullscreen);
|
|
39
41
|
|
|
@@ -111,65 +113,69 @@ public class SSOWebView {
|
|
|
111
113
|
|
|
112
114
|
@Override
|
|
113
115
|
public void onPageFinished(WebView view, String pageUrl) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
path
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
116
|
+
super.onPageFinished(view, pageUrl);
|
|
117
|
+
|
|
118
|
+
/* Guard: hanya proses sekali setelah redirect */
|
|
119
|
+
if (bodyRead) return;
|
|
120
|
+
|
|
121
|
+
Uri u = Uri.parse(pageUrl);
|
|
122
|
+
String host = u.getHost();
|
|
123
|
+
String path = u.getPath();
|
|
124
|
+
|
|
125
|
+
boolean isRedirectPage =
|
|
126
|
+
host != null && host.equalsIgnoreCase(redirectHost) &&
|
|
127
|
+
path != null && path.toLowerCase()
|
|
128
|
+
.contains(redirectPathContains.toLowerCase());
|
|
129
|
+
|
|
130
|
+
if (!isRedirectPage) return;
|
|
131
|
+
|
|
132
|
+
/* Set flag SEGERA — cegah double-fire */
|
|
133
|
+
bodyRead = true;
|
|
134
|
+
|
|
135
|
+
final String finalUrl = pageUrl;
|
|
136
|
+
final String finalCode = u.getQueryParameter("code") != null
|
|
137
|
+
? u.getQueryParameter("code") : "";
|
|
138
|
+
final String finalState = u.getQueryParameter("state") != null
|
|
139
|
+
? u.getQueryParameter("state") : "";
|
|
140
|
+
|
|
141
|
+
/* Delay 150ms — beri waktu body JSON ter-render ke DOM */
|
|
142
|
+
view.postDelayed(new Runnable() {
|
|
143
|
+
@Override
|
|
144
|
+
public void run() {
|
|
145
|
+
if (webView == null) return;
|
|
146
|
+
webView.evaluateJavascript(
|
|
147
|
+
"(function(){" +
|
|
148
|
+
" var t = document.body" +
|
|
149
|
+
" ? (document.body.innerText || document.body.textContent || '')" +
|
|
150
|
+
" : '';" +
|
|
151
|
+
" return t.trim();" +
|
|
152
|
+
"})()",
|
|
153
|
+
value -> {
|
|
154
|
+
String body = value;
|
|
155
|
+
if (body != null) {
|
|
156
|
+
if (body.startsWith("\"") && body.endsWith("\""))
|
|
157
|
+
body = body.substring(1, body.length() - 1);
|
|
158
|
+
body = body.replace("\\\"", "\"")
|
|
159
|
+
.replace("\\n", "\n")
|
|
160
|
+
.replace("\\r", "")
|
|
161
|
+
.replace("\\/", "/");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
final String finalBody = (body != null) ? body : "";
|
|
165
|
+
android.util.Log.d("SSOWebView",
|
|
166
|
+
"body len=" + finalBody.length() +
|
|
167
|
+
" preview=" + finalBody.substring(
|
|
168
|
+
0, Math.min(120, finalBody.length())));
|
|
169
|
+
|
|
170
|
+
activity.runOnUiThread(() -> SSOWebView.this.dismiss());
|
|
171
|
+
|
|
172
|
+
if (listener != null)
|
|
173
|
+
listener.onRedirectIntercepted(
|
|
174
|
+
finalUrl, finalCode, finalState, finalBody);
|
|
175
|
+
}
|
|
176
|
+
);
|
|
169
177
|
}
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
}, 150);
|
|
178
|
+
}, 150);
|
|
173
179
|
}
|
|
174
180
|
|
|
175
181
|
private void dismiss() {
|