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
- super.onPageFinished(view, pageUrl);
116
-
117
- Uri u = Uri.parse(pageUrl);
118
- String host = u.getHost();
119
- String path = u.getPath();
120
-
121
- boolean isRedirectPage = host != null && host.equalsIgnoreCase(redirectHost) &&
122
- path != null && path.toLowerCase()
123
- .contains(redirectPathContains.toLowerCase());
124
-
125
- if (!isRedirectPage)
126
- return;
127
-
128
- final String finalUrl = pageUrl;
129
- final String finalCode = u.getQueryParameter("code") != null ?
130
- u.getQueryParameter("code") :
131
- "";
132
- final String finalState = u.getQueryParameter("state") != null ?
133
- u.getQueryParameter("state") :
134
- "";
135
-
136
- /* Delay 150ms — beri waktu body JSON ter-render ke DOM */
137
- view.postDelayed(new Runnable() {
138
- @Override
139
- public void run() {
140
- if (webView == null) return;
141
- webView.evaluateJavascript(
142
- "(function(){" +
143
- " var t = document.body" +
144
- " ? (document.body.innerText || document.body.textContent || '')" +
145
- " : '';" +
146
- " return t.trim();" +
147
- "})()",
148
- value -> {
149
- String body = value;
150
- if (body != null) {
151
- if (body.startsWith("\"") && body.endsWith("\""))
152
- body = body.substring(1, body.length() - 1);
153
- body = body.replace("\\\"", "\"")
154
- .replace("\\n", "\n")
155
- .replace("\\r", "")
156
- .replace("\\/", "/");
157
- }
158
- final String finalBody = (body != null) ? body : "";
159
- android.util.Log.d("SSOWebView",
160
- "body len=" + finalBody.length() +
161
- " preview=" + finalBody.substring(
162
- 0, Math.min(120, finalBody.length())));
163
-
164
- /* FIX: gunakan outer class reference */
165
- activity.runOnUiThread(() -> SSOWebView.this.dismiss());
166
-
167
- if (listener != null)
168
- listener.onRedirectIntercepted(
169
- finalUrl, finalCode, finalState, finalBody);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-sso-webview",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "SSO WebView with URL intercept",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",