use of com.microsoft.identity.common.internal.providers.oauth2.TokenRequest in project styx by spotify.
the class ManagedServiceAccountKeyCredential method requestToken.
private TokenResponse requestToken(String signedJwt) throws IOException {
var tokenRequest = new TokenRequest(Utils.getDefaultTransport(), Utils.getDefaultJsonFactory(), new GenericUrl(getTokenServerEncodedUrl()), "urn:ietf:params:oauth:grant-type:jwt-bearer");
tokenRequest.put("assertion", signedJwt);
return tokenRequest.execute();
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenRequest in project microsoft-authentication-library-common-for-android by AzureAD.
the class BaseController method performSilentTokenRequest.
protected TokenResult performSilentTokenRequest(@SuppressWarnings(WarningType.rawtype_warning) @NonNull final OAuth2Strategy strategy, @NonNull final RefreshTokenRecord refreshToken, @NonNull final SilentTokenCommandParameters parameters) throws ClientException, IOException {
final String methodName = ":performSilentTokenRequest";
Logger.info(TAG + methodName, "Requesting tokens...");
HttpWebRequest.throwIfNetworkNotAvailable(parameters.getAndroidApplicationContext(), parameters.isPowerOptCheckEnabled());
// Check that the authority is known
final Authority.KnownAuthorityResult authorityResult = Authority.getKnownAuthorityResult(parameters.getAuthority());
if (!authorityResult.getKnown()) {
throw authorityResult.getClientException();
}
final TokenRequest refreshTokenRequest = strategy.createRefreshTokenRequest(parameters.getAuthenticationScheme());
refreshTokenRequest.setClientId(parameters.getClientId());
refreshTokenRequest.setScope(TextUtils.join(" ", parameters.getScopes()));
refreshTokenRequest.setRefreshToken(refreshToken.getSecret());
if (refreshTokenRequest instanceof MicrosoftTokenRequest) {
((MicrosoftTokenRequest) refreshTokenRequest).setClaims(parameters.getClaimsRequestJson());
((MicrosoftTokenRequest) refreshTokenRequest).setClientAppName(parameters.getApplicationName());
((MicrosoftTokenRequest) refreshTokenRequest).setClientAppVersion(parameters.getApplicationVersion());
}
// NOTE: this should be moved to the strategy; however requires a larger refactor
if (parameters.getSdkType() == SdkType.ADAL) {
((MicrosoftTokenRequest) refreshTokenRequest).setIdTokenVersion("1");
}
// Set Broker version to Token Request if it's a brokered request.
if (parameters instanceof BrokerSilentTokenCommandParameters) {
((MicrosoftTokenRequest) refreshTokenRequest).setBrokerVersion(((BrokerSilentTokenCommandParameters) parameters).getBrokerVersion());
}
if (!StringExtensions.isNullOrBlank(refreshTokenRequest.getScope())) {
Logger.infoPII(TAG + methodName, "Scopes: [" + refreshTokenRequest.getScope() + "]");
}
return strategyRequestToken(strategy, refreshTokenRequest);
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenRequest in project microsoft-authentication-library-common-for-android by AzureAD.
the class BaseController method performTokenRequest.
protected TokenResult performTokenRequest(@SuppressWarnings(WarningType.rawtype_warning) @NonNull final OAuth2Strategy strategy, @SuppressWarnings(WarningType.rawtype_warning) @NonNull final AuthorizationRequest request, @NonNull final AuthorizationResponse response, @NonNull final InteractiveTokenCommandParameters parameters) throws IOException, ClientException {
final String methodName = ":performTokenRequest";
HttpWebRequest.throwIfNetworkNotAvailable(parameters.getAndroidApplicationContext(), parameters.isPowerOptCheckEnabled());
// Suppressing unchecked warnings due to casting of type AuthorizationRequest to GenericAuthorizationRequest and AuthorizationResponse to GenericAuthorizationResponse in arguments of method call to createTokenRequest
@SuppressWarnings(WarningType.unchecked_warning) final TokenRequest tokenRequest = strategy.createTokenRequest(request, response, parameters.getAuthenticationScheme());
if (tokenRequest instanceof MicrosoftTokenRequest) {
((MicrosoftTokenRequest) tokenRequest).setClientAppName(parameters.getApplicationName());
((MicrosoftTokenRequest) tokenRequest).setClientAppVersion(parameters.getApplicationVersion());
}
if (tokenRequest instanceof IHasExtraParameters && parameters instanceof IHasExtraParameters) {
((IHasExtraParameters) tokenRequest).setExtraParameters(((IHasExtraParameters) parameters).getExtraParameters());
}
logExposedFieldsOfObject(TAG + methodName, tokenRequest);
// Suppressing unchecked warnings due to casting of type TokenRequest to GenericTokenRequest in argument of method call to requestToken
@SuppressWarnings(WarningType.unchecked_warning) final TokenResult tokenResult = strategy.requestToken(tokenRequest);
logResult(TAG, tokenResult);
return tokenResult;
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenRequest in project microsoft-authentication-library-common-for-android by AzureAD.
the class ObjectMapperTest method test_JsonToObject.
@Test
public void test_JsonToObject() {
TokenRequest tr = ObjectMapper.deserializeJsonStringToObject(JSON_TOKEN_REQUEST, TokenRequest.class);
Assert.assertEquals(CLIENT_ID, tr.getClientId());
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenRequest in project microsoft-authentication-library-common-for-android by AzureAD.
the class MockDelayedResponseStrategy method performTokenRequest.
@Override
protected HttpResponse performTokenRequest(final MicrosoftStsTokenRequest tokenRequest) {
final TokenResult tokenResult = getTokenResult();
final TokenResponse tokenResponse = tokenResult.getTokenResponse();
try {
Thread.sleep(RESPONSE_DELAY);
} catch (InterruptedException e) {
e.printStackTrace();
}
final HttpResponse httpResponse = makeHttpResponseFromResponseObject(tokenResponse);
return httpResponse;
}
Aggregations