mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-22 19:01:30 +00:00
Load UI with Authorization header (#1982)
As preparation for https://github.com/syncthing/syncthing/pull/8757. See https://github.com/syncthing/syncthing/pull/8757#issuecomment-1750372399 The app sends the `Authorization: Basic <base64-ui-credentials>` HTTP header in the initial request when loading the Web UI to skip the login form.
This commit is contained in:
parent
2ff421a166
commit
e8ef250150
1 changed files with 10 additions and 5 deletions
|
@ -1,5 +1,7 @@
|
|||
package com.nutomic.syncthingandroid.activities;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
|
@ -13,6 +15,7 @@ import android.os.Bundle;
|
|||
import android.os.IBinder;
|
||||
import android.os.Parcelable;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.webkit.HttpAuthHandler;
|
||||
|
@ -43,6 +46,8 @@ import java.security.SignatureException;
|
|||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
|
@ -99,10 +104,6 @@ public class WebGuiActivity extends StateDialogActivity
|
|||
}
|
||||
}
|
||||
|
||||
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
|
||||
handler.proceed(mConfig.getUserName(), mConfig.getApiKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
Uri uri = Uri.parse(url);
|
||||
|
@ -171,7 +172,11 @@ public class WebGuiActivity extends StateDialogActivity
|
|||
if (mWebView.getUrl() == null) {
|
||||
mWebView.stopLoading();
|
||||
setWebViewProxy(mWebView.getContext().getApplicationContext(), "", 0, "localhost|0.0.0.0|127.*|[::1]");
|
||||
mWebView.loadUrl(getService().getWebGuiUrl().toString());
|
||||
String credentials = mConfig.getUserName() + ":" + mConfig.getApiKey();
|
||||
String b64Credentials = Base64.encodeToString(credentials.getBytes(UTF_8), Base64.NO_WRAP);
|
||||
Map<String,String> headers = new HashMap<>();
|
||||
headers.put("Authorization", "Basic " + b64Credentials);
|
||||
mWebView.loadUrl(getService().getWebGuiUrl().toString(), headers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue