Cleanup of VerifyAuthenticationTask

This commit is contained in:
Peter Stuifzand 2018-04-22 00:32:35 +02:00
parent a009adddc9
commit bdee44ab8e

View File

@ -1,6 +1,5 @@
package eu.stuifzand.micropub.auth; package eu.stuifzand.micropub.auth;
import android.accounts.Account;
import android.accounts.AccountAuthenticatorResponse; import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.content.Intent; import android.content.Intent;
@ -97,10 +96,7 @@ public class VerifyAuthenticationTask extends AsyncTask<String, Void, VerifyAuth
return new AuthenticationResult("Unsuccessful response from authorization_endpoint: HTTP status code is " + String.valueOf(response.code())); return new AuthenticationResult("Unsuccessful response from authorization_endpoint: HTTP status code is " + String.valueOf(response.code()));
} }
ResponseBody body = response.body(); ResponseBody body = response.body();
if (!response.header("Content-Type").contains("application/json")) { if (response.header("Content-Type").contains("application/json")) {
return new AuthenticationResult("Unsupported content type of authorization_endpoint response: " + response.header("Content-Type"));
}
JsonParser parser = new JsonParser(); JsonParser parser = new JsonParser();
try { try {
JsonElement jsonElement = parser.parse(body.string()); JsonElement jsonElement = parser.parse(body.string());
@ -115,6 +111,8 @@ public class VerifyAuthenticationTask extends AsyncTask<String, Void, VerifyAuth
} catch (JsonParseException e) { } catch (JsonParseException e) {
return new AuthenticationResult("Could not parse json response from authorization_endpoint"); return new AuthenticationResult("Could not parse json response from authorization_endpoint");
} }
}
return new AuthenticationResult("Unsupported content type of authorization_endpoint response: " + response.header("Content-Type"));
} catch (IOException e) { } catch (IOException e) {
return new AuthenticationResult("Could not get the response from the endpoint"); return new AuthenticationResult("Could not get the response from the endpoint");
} finally { } finally {