use of com.microsoft.identity.common.internal.result.GenerateShrResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class DevicePoPUtils method generateSignedHttpRequest.
/**
* Generates an AT-less SHR using the PoPMgr's internal signing key.
*
* @param context The current application's {@link Context}.
* @param clockSkewManager An instance of {@link IClockSkewManager}, used to mitigate
* clock-skew/drift.
* @param popSchemeParams The input params used to create the resulting SHR.
* @return The {@link GenerateShrResult} containing the resulint SHR.
* @throws ClientException If an error is encountered.
*/
public static synchronized GenerateShrResult generateSignedHttpRequest(@NonNull final Context context, @NonNull final IClockSkewManager clockSkewManager, @NonNull final IPoPAuthenticationSchemeParams popSchemeParams) throws ClientException {
// Clock-skew correction values
final long ONE_SECOND_MILLIS = 1000L;
final long timestampMillis = clockSkewManager.getAdjustedReferenceTime().getTime();
final String httpMethodStr = popSchemeParams.getHttpMethod();
final URL resourceUrl = popSchemeParams.getUrl();
final String nonce = popSchemeParams.getNonce();
final String clientClaims = popSchemeParams.getClientClaims();
final IDevicePopManager popMgr = Device.getDevicePoPManagerInstance();
// Generate keys, if none exist (should already be initialized)
if (!popMgr.asymmetricKeyExists()) {
popMgr.generateAsymmetricKey(context);
}
final String shr = popMgr.mintSignedHttpRequest(httpMethodStr, timestampMillis / ONE_SECOND_MILLIS, resourceUrl, nonce, clientClaims);
// Create our result object
final GenerateShrResult result = new GenerateShrResult();
result.setShr(shr);
return result;
}
use of com.microsoft.identity.common.internal.result.GenerateShrResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class LocalMSALController method generateSignedHttpRequest.
@Override
public GenerateShrResult generateSignedHttpRequest(@NonNull final GenerateShrCommandParameters parameters) throws Exception {
final Context context = parameters.getAndroidApplicationContext();
final IClockSkewManager clockSkewManager = new ClockSkewManager(context);
final OAuth2TokenCache cache = parameters.getOAuth2TokenCache();
final String clientId = parameters.getClientId();
final String homeAccountId = parameters.getHomeAccountId();
final IPoPAuthenticationSchemeParams popSchemeParams = parameters.getPopParameters();
final GenerateShrResult result;
if (userHasLocalAccountRecord(cache, clientId, homeAccountId)) {
// Perform the signing locally...
result = DevicePoPUtils.generateSignedHttpRequest(context, clockSkewManager, popSchemeParams);
} else {
// Populate the error on the result and return...
result = new GenerateShrResult();
result.setErrorCode(GenerateShrResult.Errors.NO_ACCOUNT_FOUND);
result.setErrorMessage("Account does not exist.");
}
return result;
}
use of com.microsoft.identity.common.internal.result.GenerateShrResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class GenerateShrCommand method execute.
@Override
public GenerateShrResult execute() throws Exception {
final String methodName = ":execute";
GenerateShrResult result = null;
final GenerateShrCommandParameters parameters = (GenerateShrCommandParameters) getParameters();
// Iterate over our controllers, to service the request either locally or via the broker...
// if the local (embedded) cache contains tokens for the supplied user, we will sign using
// the embedded PoP keys. If no local user-state exists, the broker will be delegated to
// where the same check is performed.
BaseController controller;
for (int ii = 0; ii < getControllers().size(); ii++) {
controller = getControllers().get(ii);
com.microsoft.identity.common.internal.logging.Logger.verbose(TAG + methodName, "Executing with controller: " + controller.getClass().getSimpleName());
result = controller.generateSignedHttpRequest(parameters);
if (null != result.getErrorCode()) {
final String errorCode = result.getErrorCode();
final String errorMessage = result.getErrorMessage();
// of as thrown Exceptions
if (NO_ACCOUNT_FOUND.equalsIgnoreCase(errorCode)) {
if (getControllers().size() > ii + 1) {
// Try our next controller
continue;
} else {
throw new UiRequiredException(errorCode, errorMessage);
}
} else {
throw new ClientException(errorCode, errorMessage);
}
}
}
return result;
}
Aggregations