Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/plugins/auth/src/android/Authenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ public class Authenticator extends CordovaPlugin {
private static final String PREFS_FILENAME = "acode_auth_secure";
private static final String KEY_TOKEN = "auth_token";
private static final String PRO_PURCHASED = "pro_purchased";
private static final String KEY_MIGRATED_V2 = "migrated_host_to_domain_cookies";
private static final String[] API_ORIGINS = {
"https://acode.app"
};
private static final String[] LEGACY_ORIGINS = {
"https://acode.app",
"https://dev.acode.app"
};
Expand All @@ -27,6 +31,12 @@ protected void pluginInitialize() {
WebView androidWebView = (WebView) webView.getView();
CookieManager.getInstance().setAcceptThirdPartyCookies(androidWebView, true);

if (!prefManager.getBoolean(KEY_MIGRATED_V2, false)) {
Log.d(TAG, "Migrating: clearing legacy host-scoped cookies");
clearLegacyCookies();
prefManager.setBoolean(KEY_MIGRATED_V2, true);
}

String token = prefManager.getString(KEY_TOKEN, "");
if (!token.isEmpty()) {
setTokenCookie(token);
Expand Down Expand Up @@ -59,15 +69,23 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
private void setTokenCookie(String token) {
CookieManager cm = CookieManager.getInstance();
for (String origin : API_ORIGINS) {
cm.setCookie(origin, "token=" + token + "; Path=/; Secure; HttpOnly; SameSite=None");
cm.setCookie(origin, "token=" + token + "; Domain=.acode.app; Path=/; Secure; HttpOnly; SameSite=None");
}
cm.flush();
}

private void clearTokenCookie() {
CookieManager cm = CookieManager.getInstance();
for (String origin : API_ORIGINS) {
cm.setCookie(origin, "token=; Path=/; Max-Age=0");
cm.setCookie(origin, "token=; Domain=.acode.app; Path=/; Max-Age=0; Secure; HttpOnly; SameSite=None");
}
cm.flush();
}
Comment thread
deadlyjack marked this conversation as resolved.

private void clearLegacyCookies() {
CookieManager cm = CookieManager.getInstance();
for (String origin : LEGACY_ORIGINS) {
cm.setCookie(origin, "token=; Path=/; Max-Age=0; Secure; HttpOnly; SameSite=None");
}
cm.flush();
}
Expand Down