use of com.okta.oidc.net.HttpResponse in project okta-oidc-android by okta.
the class BaseRequestTest method close.
@Test
public void close() throws Exception {
mExpectedEx.expect(IOException.class);
if (mClientType == USE_DEFAULT_HTTP) {
mExpectedEx.expectMessage("stream is closed");
} else {
mExpectedEx.expectMessage("closed");
}
mEndPoint.enqueueConfigurationSuccess();
mRequest.mUri = Uri.parse(mEndPoint.getUrl());
mRequest.mConnParams = new ConnectionParameters.ParameterBuilder().setRequestMethod(ConnectionParameters.RequestMethod.GET).create();
HttpResponse response = mRequest.openConnection(mHttpClient);
mRequest.close();
response.getContent().read();
}
use of com.okta.oidc.net.HttpResponse in project okta-oidc-android by okta.
the class BaseRequestTest method openConnection.
@Test
public void openConnection() throws Exception {
mEndPoint.enqueueReturnSuccessEmptyBody();
mRequest.mUri = Uri.parse(mEndPoint.getUrl());
mRequest.mConnParams = new ConnectionParameters.ParameterBuilder().setRequestMethod(ConnectionParameters.RequestMethod.GET).create();
HttpResponse response = mRequest.openConnection(mHttpClient);
assertEquals(response.getStatusCode(), HTTP_OK);
}
use of com.okta.oidc.net.HttpResponse in project okta-oidc-android by okta.
the class AuthorizedRequest method executeRequest.
@Override
public JSONObject executeRequest(OktaHttpClient client) throws AuthorizationException {
AuthorizationException exception = null;
HttpResponse response = null;
try {
response = openConnection(client);
return response.asJson();
} catch (IOException io) {
exception = new AuthorizationException(io.getMessage(), io);
} catch (JSONException je) {
exception = AuthorizationException.fromTemplate(AuthorizationException.GeneralErrors.JSON_DESERIALIZATION_ERROR, je);
} catch (Exception e) {
exception = AuthorizationException.fromTemplate(AuthorizationException.GeneralErrors.NETWORK_ERROR, e);
} finally {
if (response != null) {
response.disconnect();
}
if (exception != null) {
throw exception;
}
}
return null;
}
use of com.okta.oidc.net.HttpResponse in project okta-oidc-android by okta.
the class NativeAuthorizeRequest method executeRequest.
@Override
public AuthorizeResponse executeRequest(OktaHttpClient client) throws AuthorizationException {
AuthorizationException exception = null;
HttpResponse response = null;
try {
response = openConnection(client);
if (response.getStatusCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
exception = AuthorizationException.TokenRequestErrors.INVALID_CLIENT;
} else if (response.getStatusCode() == HttpURLConnection.HTTP_OK || response.getStatusCode() == HttpURLConnection.HTTP_MOVED_TEMP) {
Uri locationUri = Uri.parse(response.getHeaderField("Location"));
return AuthorizeResponse.fromUri(locationUri);
}
} catch (IOException ex) {
exception = new AuthorizationException(ex.getMessage(), ex);
} catch (Exception e) {
exception = new AuthorizationException(e.getMessage(), e);
} finally {
if (response != null) {
response.disconnect();
}
if (exception != null) {
throw exception;
}
}
return null;
}
use of com.okta.oidc.net.HttpResponse in project okta-oidc-android by okta.
the class TokenRequest method executeRequest.
@Override
public TokenResponse executeRequest(OktaHttpClient client) throws AuthorizationException {
HttpResponse response = null;
TokenResponse tokenResponse;
try {
response = openConnection(client);
JSONObject json = response.asJsonWithErrorDescription();
if (json.has(AuthorizationException.PARAM_ERROR)) {
try {
final String error = json.getString(AuthorizationException.PARAM_ERROR);
throw AuthorizationException.fromOAuthTemplate(AuthorizationException.TokenRequestErrors.byString(error), error, json.optString(AuthorizationException.PARAM_ERROR_DESCRIPTION, null), UriUtil.parseUriIfAvailable(json.optString(AuthorizationException.PARAM_ERROR_URI)));
} catch (JSONException jsonEx) {
throw AuthorizationException.fromTemplate(AuthorizationException.GeneralErrors.JSON_DESERIALIZATION_ERROR, jsonEx);
}
}
tokenResponse = new Gson().fromJson(json.toString(), TokenResponse.class);
tokenResponse.setCreationTime(System.currentTimeMillis());
if (tokenResponse.getIdToken() != null) {
OktaIdToken idToken;
try {
idToken = OktaIdToken.parseIdToken(tokenResponse.getIdToken());
} catch (IllegalArgumentException | JsonIOException ex) {
Log.e(TAG, "", ex);
throw AuthorizationException.fromTemplate(AuthorizationException.GeneralErrors.ID_TOKEN_PARSING_ERROR, ex);
}
idToken.validate(this, mConfig.getIdTokenValidator());
}
return tokenResponse;
} catch (IOException ex) {
throw new AuthorizationException(ex.getMessage(), ex);
} catch (JSONException ex) {
throw AuthorizationException.fromTemplate(AuthorizationException.GeneralErrors.JSON_DESERIALIZATION_ERROR, ex);
} catch (AuthorizationException ae) {
throw ae;
} catch (Exception e) {
throw AuthorizationException.fromTemplate(AuthorizationException.GeneralErrors.NETWORK_ERROR, e);
} finally {
if (response != null) {
response.disconnect();
}
}
}
Aggregations