Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the back-compat of hello() #606

Merged
merged 4 commits into from
Aug 24, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ private class SerializedNames {
static final String CACHED_AT = "cached_at";
static final String REFRESH_TOKEN_AGE = "refresh_token_age";
static final String SUCCESS = "success";
static final String NEGOTIATED_BROKER_PROTOCOL_VERSION = "negotiated.broker.protocol.version.name";

// Error constants
/**
Expand Down Expand Up @@ -85,6 +84,8 @@ private class SerializedNames {
static final String CLI_TELEM_SUB_ERROR_CODE = "cli_telem_suberror_code";
}

private static final long serialVersionUID = 8606631820514878489L;
heidijinxujia marked this conversation as resolved.
Show resolved Hide resolved

// Success parameters
/**
* Access token from the response
Expand Down Expand Up @@ -221,13 +222,6 @@ private class SerializedNames {
@SerializedName(SerializedNames.REFRESH_TOKEN_AGE)
private String mRefreshTokenAge;

/**
* Negotiated broker protocol version between broker client and broker service.
*/
@Nullable
@SerializedName(SerializedNames.NEGOTIATED_BROKER_PROTOCOL_VERSION)
private String mNegotiatedBrokerProtocolVersion;

/**
* Boolean to indicate if the request succeeded without exceptions.
*/
Expand Down Expand Up @@ -328,7 +322,6 @@ private BrokerResult(@NonNull final Builder builder) {
mRefreshTokenAge = builder.mRefreshTokenAge;
mSuccess = builder.mSuccess;
mTenantProfileData = builder.mTenantProfileData;
mNegotiatedBrokerProtocolVersion = builder.mNegotiatedBrokerProtocolVersion;

mErrorCode = builder.mErrorCode;
mErrorMessage = builder.mErrorMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.microsoft.identity.common.internal.request.SdkType;
import com.microsoft.identity.common.internal.util.HeaderSerializationUtil;
import com.microsoft.identity.common.internal.util.ICacheRecordGsonAdapter;
import com.microsoft.identity.common.internal.util.StringUtil;

import org.json.JSONException;

Expand Down Expand Up @@ -176,6 +177,33 @@ public static BrokerResult brokerResultFromBundle(@NonNull final Bundle resultBu
);
}

public static boolean getHelloResultFromBundle(final Bundle bundle) throws ClientException {
final String methodName = ":getHelloResultFromBundle";
if (bundle == null) {
Logger.warn(TAG + methodName, "The hello result bundle is null.");
return false;
} else if (!StringUtil.isEmpty(bundle.getString(AuthenticationConstants.Broker.NEGOTIATED_BP_VERSION_KEY))) {
heidijinxujia marked this conversation as resolved.
Show resolved Hide resolved
final String negotiatedBrokerProtocolVersion = bundle.getString(AuthenticationConstants.Broker.NEGOTIATED_BP_VERSION_KEY);
Logger.verbose(TAG + methodName,
"Able to establish the connect, " +
"the broker protocol version in common is ["
+ negotiatedBrokerProtocolVersion + "]");
return true;
} else if (!StringUtil.isEmpty(bundle.getString(AuthenticationConstants.OAuth2.ERROR))
&& !StringUtil.isEmpty(bundle.getString(AuthenticationConstants.OAuth2.ERROR_DESCRIPTION))) {
final String errorCode = bundle.getString(AuthenticationConstants.OAuth2.ERROR);
final String errorMessage = bundle.getString(AuthenticationConstants.OAuth2.ERROR_DESCRIPTION);
throw new ClientException(errorCode, errorMessage);
} else if (bundle.get(AuthenticationConstants.Broker.BROKER_RESULT_V2) != null
&& bundle.get(AuthenticationConstants.Broker.BROKER_RESULT_V2) instanceof BrokerResult) {
// for the back compatibility purpose to version 3.0.4 and 3.0.6.
final BrokerResult brokerResult = (BrokerResult) bundle.get(AuthenticationConstants.Broker.BROKER_RESULT_V2);
throw new ClientException(brokerResult.getErrorCode(), brokerResult.getErrorMessage());
} else {
return false;
}
}

@Override
public BaseException baseExceptionFromBundle(@NonNull final Bundle resultBundle) {
Logger.verbose(TAG, "Constructing exception from result bundle");
Expand Down