linked: fix screwups from last commit, sigh

This commit is contained in:
Vincent Breitmoser
2015-09-10 02:11:43 +02:00
parent 7fa1afe430
commit 0f4af7d2ed

View File

@@ -244,18 +244,19 @@ public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKe
} }
if (result != null) { if (result != null) {
Notify.create(activity, "Authorization failed!", Style.ERROR); Notify.create(activity, "Authorization failed!", Style.ERROR).show();
return; return;
} }
if (mException instanceof SocketTimeoutException) { if (mException instanceof SocketTimeoutException) {
Notify.create(activity, "Connection timeout!", Style.ERROR); Notify.create(activity, "Connection timeout!", Style.ERROR).show();
} else if (mException instanceof HttpResultException) { } else if (mException instanceof HttpResultException) {
// we have the error code here.. should we use it? // we have the error code here.. should we use it?
Notify.create(activity, Notify.create(activity,
"Communication error: " + ((HttpResultException) mException).mResponse, Style.ERROR); "Communication error: " + ((HttpResultException) mException).mResponse,
Style.ERROR).show();
} else if (mException instanceof IOException) { } else if (mException instanceof IOException) {
Notify.create(activity, "Network error!", Style.ERROR); Notify.create(activity, "Network error!", Style.ERROR).show();
} }
return; return;
@@ -330,13 +331,14 @@ public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKe
} }
if (mException instanceof SocketTimeoutException) { if (mException instanceof SocketTimeoutException) {
Notify.create(activity, "Connection timeout!", Style.ERROR); Notify.create(activity, "Connection timeout!", Style.ERROR).show();
} else if (mException instanceof HttpResultException) { } else if (mException instanceof HttpResultException) {
// we have the error code here.. should we use it? // we have the error code here.. should we use it?
Notify.create(activity, Notify.create(activity,
"Communication error: " + ((HttpResultException) mException).mResponse, Style.ERROR); "Communication error: " + ((HttpResultException) mException).mResponse,
Style.ERROR).show();
} else if (mException instanceof IOException) { } else if (mException instanceof IOException) {
Notify.create(activity, "Network error!", Style.ERROR); Notify.create(activity, "Network error!", Style.ERROR).show();
} }
return; return;
@@ -513,6 +515,7 @@ public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKe
byte[] buf = new byte[16]; byte[] buf = new byte[16];
new Random().nextBytes(buf); new Random().nextBytes(buf);
mOAuthState = new String(Hex.encode(buf)); mOAuthState = new String(Hex.encode(buf));
mOAuthCode = null;
final Dialog auth_dialog = new Dialog(activity); final Dialog auth_dialog = new Dialog(activity);
auth_dialog.setContentView(R.layout.oauth_webview); auth_dialog.setContentView(R.layout.oauth_webview);
@@ -526,6 +529,10 @@ public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKe
Uri uri = Uri.parse(url); Uri uri = Uri.parse(url);
if ("oauth-openkeychain".equals(uri.getScheme())) { if ("oauth-openkeychain".equals(uri.getScheme())) {
if (mOAuthCode != null) {
return true;
}
if (uri.getQueryParameter("error") != null) { if (uri.getQueryParameter("error") != null) {
Log.i(Constants.TAG, "ACCESS_DENIED_HERE"); Log.i(Constants.TAG, "ACCESS_DENIED_HERE");
auth_dialog.dismiss(); auth_dialog.dismiss();
@@ -539,7 +546,7 @@ public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKe
return true; return true;
} }
// don't surf away from github! // don't surf away from github!
if ( ! "github.com".equals(uri.getHost())) { if (!"github.com".equals(uri.getHost())) {
auth_dialog.dismiss(); auth_dialog.dismiss();
return true; return true;
} }
@@ -638,7 +645,8 @@ public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKe
nection.connect(); nection.connect();
if (nection.getResponseCode() != 200) { int code = nection.getResponseCode();
if (code != HttpsURLConnection.HTTP_CREATED && code != HttpsURLConnection.HTTP_OK) {
throw new HttpResultException(nection.getResponseCode(), nection.getResponseMessage()); throw new HttpResultException(nection.getResponseCode(), nection.getResponseMessage());
} }