fixed 404 error when login using custom api proxy
This commit is contained in:
parent
0b32629de5
commit
947d250dd9
|
@ -256,6 +256,7 @@ public interface SharedPreferenceConstants {
|
||||||
String KEY_SETTINGS_WIZARD_COMPLETED = "settings_wizard_completed";
|
String KEY_SETTINGS_WIZARD_COMPLETED = "settings_wizard_completed";
|
||||||
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = true)
|
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = true)
|
||||||
String KEY_CARD_ANIMATION = "card_animation";
|
String KEY_CARD_ANIMATION = "card_animation";
|
||||||
|
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = true)
|
||||||
String KEY_UNREAD_COUNT = "unread_count";
|
String KEY_UNREAD_COUNT = "unread_count";
|
||||||
String KEY_NOTIFICATION = "notification";
|
String KEY_NOTIFICATION = "notification";
|
||||||
String KEY_NOTIFICATION_TYPE_HOME = "notification_type_home";
|
String KEY_NOTIFICATION_TYPE_HOME = "notification_type_home";
|
||||||
|
@ -302,7 +303,9 @@ public interface SharedPreferenceConstants {
|
||||||
|
|
||||||
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = false)
|
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = false)
|
||||||
String KEY_THUMBOR_ENABLED = "thumbor_enabled";
|
String KEY_THUMBOR_ENABLED = "thumbor_enabled";
|
||||||
|
@Preference(type = STRING, hasDefault = false)
|
||||||
String KEY_THUMBOR_ADDRESS = "thumbor_address";
|
String KEY_THUMBOR_ADDRESS = "thumbor_address";
|
||||||
|
@Preference(type = STRING, hasDefault = false)
|
||||||
String KEY_THUMBOR_SECURITY_KEY = "thumbor_security_key";
|
String KEY_THUMBOR_SECURITY_KEY = "thumbor_security_key";
|
||||||
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = false)
|
@Preference(type = BOOLEAN, hasDefault = true, defaultBoolean = false)
|
||||||
String KEY_HIDE_CARD_ACTIONS = "hide_card_actions";
|
String KEY_HIDE_CARD_ACTIONS = "hide_card_actions";
|
||||||
|
|
|
@ -714,7 +714,7 @@ class ConfigurationBase implements TwitterConstants, Configuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOAuthAuthorizationURL(String oAuthAuthorizationURL) {
|
public void setOAuthAuthorizationURL(String oAuthAuthorizationURL) {
|
||||||
// this.oAuthAuthorizationURL = oAuthAuthorizationURL;
|
this.oAuthAuthorizationURL = oAuthAuthorizationURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void setOAuthBaseURL(String oAuthBaseURL) {
|
protected final void setOAuthBaseURL(String oAuthBaseURL) {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.xmlpull.v1.XmlPullParserFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.net.HttpCookie;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -89,8 +90,20 @@ public class OAuthPasswordAuthenticator implements Constants {
|
||||||
final HeaderMap requestHeaders = new HeaderMap();
|
final HeaderMap requestHeaders = new HeaderMap();
|
||||||
requestHeaders.addHeader("Origin", "https://twitter.com");
|
requestHeaders.addHeader("Origin", "https://twitter.com");
|
||||||
requestHeaders.addHeader("Referer", "https://twitter.com/oauth/authorize?oauth_token=" + requestToken.getToken());
|
requestHeaders.addHeader("Referer", "https://twitter.com/oauth/authorize?oauth_token=" + requestToken.getToken());
|
||||||
requestHeaders.put("Cookie", cookieHeaders);
|
final List<String> modifiedCookieHeaders = new ArrayList<>();
|
||||||
final String oAuthAuthorizationUrl = conf.getOAuthAuthorizationURL();
|
final String oAuthAuthorizationUrl = conf.getOAuthAuthorizationURL();
|
||||||
|
|
||||||
|
final String host = parseUrlHost(oAuthAuthorizationUrl);
|
||||||
|
for (String cookieHeader : cookieHeaders) {
|
||||||
|
for (HttpCookie cookie : HttpCookie.parse(cookieHeader)) {
|
||||||
|
if (HttpCookie.domainMatches(cookie.getDomain(), host)) {
|
||||||
|
cookie.setVersion(1);
|
||||||
|
cookie.setDomain("twitter.com");
|
||||||
|
}
|
||||||
|
modifiedCookieHeaders.add(cookie.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
requestHeaders.put("Cookie", modifiedCookieHeaders);
|
||||||
final String oauthPin = readOAuthPINFromHtml(client.post(oAuthAuthorizationUrl, oAuthAuthorizationUrl,
|
final String oauthPin = readOAuthPINFromHtml(client.post(oAuthAuthorizationUrl, oAuthAuthorizationUrl,
|
||||||
params.toArray(new HttpParameter[params.size()]), requestHeaders).asReader());
|
params.toArray(new HttpParameter[params.size()]), requestHeaders).asReader());
|
||||||
if (isEmpty(oauthPin)) throw new WrongUserPassException();
|
if (isEmpty(oauthPin)) throw new WrongUserPassException();
|
||||||
|
@ -100,7 +113,7 @@ public class OAuthPasswordAuthenticator implements Constants {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void readInputFromHtml(final Reader in, Map<String, String> map, String... desiredNames) throws IOException, XmlPullParserException {
|
private static void readInputFromHtml(final Reader in, Map<String, String> map, String... desiredNames) throws IOException, XmlPullParserException {
|
||||||
final XmlPullParserFactory f = XmlPullParserFactory.newInstance();
|
final XmlPullParserFactory f = XmlPullParserFactory.newInstance();
|
||||||
final XmlPullParser parser = f.newPullParser();
|
final XmlPullParser parser = f.newPullParser();
|
||||||
parser.setFeature(Xml.FEATURE_RELAXED, true);
|
parser.setFeature(Xml.FEATURE_RELAXED, true);
|
||||||
|
@ -151,6 +164,11 @@ public class OAuthPasswordAuthenticator implements Constants {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String parseUrlHost(String url) {
|
||||||
|
final int startOfHost = url.indexOf("://") + 3, endOfHost = url.indexOf('/', startOfHost);
|
||||||
|
return url.substring(startOfHost, endOfHost);
|
||||||
|
}
|
||||||
|
|
||||||
public static class AuthenticationException extends Exception {
|
public static class AuthenticationException extends Exception {
|
||||||
|
|
||||||
private static final long serialVersionUID = -5629194721838256378L;
|
private static final long serialVersionUID = -5629194721838256378L;
|
||||||
|
|
|
@ -23,13 +23,13 @@
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center">
|
||||||
android:fitsSystemWindows="true">
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="300dp"
|
android:layout_width="300dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
android:gravity="center">
|
android:gravity="center">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
Loading…
Reference in New Issue