capacitor-sso-webview 0.0.5 → 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
|
|
|
@@ -57,8 +59,7 @@ public class SSOWebView {
|
|
|
57
59
|
tvTitle.setText(title != null ? title : "Login");
|
|
58
60
|
tvTitle.setTextColor(Color.WHITE);
|
|
59
61
|
tvTitle.setTextSize(16);
|
|
60
|
-
tvTitle.setLayoutParams(new LinearLayout.LayoutParams(
|
|
61
|
-
0, ViewGroup.LayoutParams.WRAP_CONTENT, 1 f));
|
|
62
|
+
tvTitle.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
|
|
62
63
|
|
|
63
64
|
TextView btnClose = new TextView(activity);
|
|
64
65
|
btnClose.setText("Tutup");
|
|
@@ -112,65 +113,69 @@ public class SSOWebView {
|
|
|
112
113
|
|
|
113
114
|
@Override
|
|
114
115
|
public void onPageFinished(WebView view, String pageUrl) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
path
|
|
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
|
-
|
|
169
|
-
|
|
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
|
+
);
|
|
170
177
|
}
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
}, 150);
|
|
178
|
+
}, 150);
|
|
174
179
|
}
|
|
175
180
|
|
|
176
181
|
private void dismiss() {
|
|
@@ -178,8 +183,7 @@ public class SSOWebView {
|
|
|
178
183
|
}
|
|
179
184
|
});
|
|
180
185
|
|
|
181
|
-
webView.setLayoutParams(new LinearLayout.LayoutParams(
|
|
182
|
-
ViewGroup.LayoutParams.MATCH_PARENT, 0, 1 f));
|
|
186
|
+
webView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f));
|
|
183
187
|
|
|
184
188
|
root.addView(header);
|
|
185
189
|
root.addView(webView);
|