Skip to content

Commit

Permalink
Merge refactor to dev (#347)
Browse files Browse the repository at this point in the history
* Added a new util method to StringUtil

* Refactor changes in common

* Revert "Added a new util method to StringUtil"

This reverts commit 2e37774.

* Changes to common w.r.t exceptions

* More refactor changes

* Removed todo statement

* Fix a fub in controller intilization

* Update to error strings

* Changes related to Webview redirects

* More refactor changes

* Addressing review comments

* Added default constructor

* Changes to add refresh token to Auth result
  • Loading branch information
kreedula authored Jan 29, 2019
1 parent 95ba72e commit d4f87ee
Show file tree
Hide file tree
Showing 18 changed files with 467 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private AuthenticationConstants() {
/**
* The Constant ENCODING_UTF8.
*/
public static final String ENCODING_UTF8 = "UTF_8";
public static final String ENCODING_UTF8 = "UTF-8";

/**
* Bundle message.
Expand Down Expand Up @@ -406,6 +406,11 @@ public static final class OAuth2 {
* session key JWE.
*/
public static final String SESSION_KEY_JWE = "session_key_jwe";

/**
* String as Query parameter key to send a V1 request to V2 endpoint
*/
public static final String IT_VER_PARAM = "itver";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.microsoft.identity.common.adal.internal.net.HttpWebResponse;
import com.microsoft.identity.common.internal.logging.Logger;
import com.microsoft.identity.common.internal.net.HttpResponse;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -133,6 +134,26 @@ public static HashMap<String, String> getJsonResponse(HttpWebResponse webRespons
return response;
}

/**
* get key value pairs from response.
*
* @param webResponse {@link HttpResponse} to convert to a map
* @return HashMap
* @throws JSONException
*/
public static HashMap<String, String> getJsonResponse(HttpResponse webResponse) throws JSONException {
final HashMap<String, String> response = new HashMap<>();
if (webResponse != null && !TextUtils.isEmpty(webResponse.getBody())) {
JSONObject jsonObject = new JSONObject(webResponse.getBody());
Iterator<?> i = jsonObject.keys();
while (i.hasNext()) {
String key = (String) i.next();
response.put(key, jsonObject.getString(key));
}
}
return response;
}

/**
* Parse json String into HashMap<String, String>.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class StringExtensions {
/**
* The constant ENCODING_UTF8.
*/
public static final String ENCODING_UTF8 = "UTF_8";
public static final String ENCODING_UTF8 = "UTF-8";

private static final String TAG = StringExtensions.class.getSimpleName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,35 @@ private ErrorStrings() {
* No available browser installed on the device.
*/
public static final String NO_AVAILABLE_BROWSER_FOUND = "No available browser installed on the device.";

/**
* Refresh token request failed.
*/
public static final String AUTH_REFRESH_FAILED = "Refresh token request failed";

/**
* STK patching failed.
*/
public static final String STK_PATCHING_FAILED = "STK patching failed";

/**
* Primary refresh token request failed.
*/
public static final String BROKER_PRT_REFRESH_FAILED = "Failed to refresh PRT";

/**
* Broker RT is invalid
*/
public static final String INVALID_BROKER_REFRESH_TOKEN = "Broker refresh token is invalid";

/**
* Device state of Joined account invalid.
*/
public static final String DEVICE_STATE_INVALID = "Invalid device state";

/**
* Device registration failed.
*/
public static final String DEVICE_REGISTRATION_FAILED = "Device registration failed";

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.microsoft.identity.common.adal.internal.net.HttpWebResponse;
import com.microsoft.identity.common.adal.internal.util.HashMapExtensions;
import com.microsoft.identity.common.internal.net.HttpResponse;

import org.json.JSONException;

Expand Down Expand Up @@ -79,6 +80,10 @@ public class ServiceException extends BaseException {

private HashMap<String, List<String>> mHttpResponseHeaders = null;

private String mOAuthError;

private String mOAuthErrorDescription;

/**
* When {@link java.net.SocketTimeoutException} is thrown, no status code will be caught. Will use 0 instead.
*/
Expand Down Expand Up @@ -114,20 +119,16 @@ public HashMap<String, List<String>> getHttpResponseHeaders() {
*
* @param response HttpWebResponse
*/
public void setHttpResponse(final HttpWebResponse response) {
public void setHttpResponse(final HttpResponse response) throws JSONException {
if (null != response) {
mHttpStatusCode = response.getStatusCode();

if (null != response.getResponseHeaders()) {
mHttpResponseHeaders = new HashMap<>(response.getResponseHeaders());
if (null != response.getHeaders()) {
mHttpResponseHeaders = new HashMap<>(response.getHeaders());
}

if (null != response.getBody()) {
try {
mHttpResponseBody = new HashMap<>(HashMapExtensions.getJsonResponse(response));
} catch (final JSONException exception) {
//Log.e(CommonCoreBaseException.class.getSimpleName(), ADALError.SERVER_INVALID_JSON_RESPONSE.toString(), exception);
}
}
}
}
Expand Down Expand Up @@ -156,4 +157,20 @@ public ServiceException(final String errorCode, final String errorMessage, final
super(errorCode, errorMessage, throwable);
mHttpStatusCode = httpStatusCode;
}

public String getOAuthError() {
return mOAuthError;
}

public void setOAuthError(final String oAuthError) {
this.mOAuthError = oAuthError;
}

public String getOAuthErrorDescription() {
return mOAuthErrorDescription;
}

public void setOAuthErrorDescription(final String oAuthErrorDescription) {
this.mOAuthErrorDescription = oAuthErrorDescription;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public final class UiRequiredException extends BaseException {
*/
public static final String INVALID_GRANT = "invalid_grant";

/**
* The refresh token used to redeem access token is invalid and auth code request is needed.
*/
public static final String INTERACTION_REQUIRED = "interaction_required";

/**
* Access token doesn't exist and there is no refresh token can be found to redeem access token.
*/
Expand All @@ -61,4 +66,12 @@ public UiRequiredException(final String errorCode, final String errorMessage) {
public UiRequiredException(final String errorCode, final String errorMessage, final Throwable throwable) {
super(errorCode, errorMessage, throwable);
}

public boolean isInteractionRequired(){
return getErrorCode().equalsIgnoreCase(INTERACTION_REQUIRED);
}

public boolean isInvalidGrant(){
return getErrorCode().equalsIgnoreCase(INVALID_GRANT);
}
}
Loading

0 comments on commit d4f87ee

Please sign in to comment.