Search in sources :

Example 16 with TokenRequest

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();
}
Also used : TokenRequest(com.google.api.client.auth.oauth2.TokenRequest) GenericUrl(com.google.api.client.http.GenericUrl)

Example 17 with TokenRequest

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);
}
Also used : BrokerSilentTokenCommandParameters(com.microsoft.identity.common.internal.commands.parameters.BrokerSilentTokenCommandParameters) AzureActiveDirectoryAuthority(com.microsoft.identity.common.internal.authorities.AzureActiveDirectoryAuthority) Authority(com.microsoft.identity.common.internal.authorities.Authority) MicrosoftTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenRequest) TokenRequest(com.microsoft.identity.common.internal.providers.oauth2.TokenRequest) MicrosoftTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenRequest)

Example 18 with TokenRequest

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;
}
Also used : TokenResult(com.microsoft.identity.common.internal.providers.oauth2.TokenResult) AcquireTokenResult(com.microsoft.identity.common.internal.result.AcquireTokenResult) MicrosoftTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenRequest) TokenRequest(com.microsoft.identity.common.internal.providers.oauth2.TokenRequest) MicrosoftTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenRequest) IHasExtraParameters(com.microsoft.identity.common.internal.commands.parameters.IHasExtraParameters)

Example 19 with TokenRequest

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());
}
Also used : TokenRequest(com.microsoft.identity.common.internal.providers.oauth2.TokenRequest) MicrosoftTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenRequest) Test(org.junit.Test)

Example 20 with TokenRequest

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;
}
Also used : TokenResponse(com.microsoft.identity.common.internal.providers.oauth2.TokenResponse) MockTokenResponse(com.microsoft.identity.internal.testutils.mocks.MockTokenResponse) TokenResult(com.microsoft.identity.common.internal.providers.oauth2.TokenResult) HttpResponse(com.microsoft.identity.common.internal.net.HttpResponse)

Aggregations

TokenRequest (com.microsoft.identity.common.internal.providers.oauth2.TokenRequest)10 MicrosoftStsTokenRequest (com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsTokenRequest)8 TokenResult (com.microsoft.identity.common.internal.providers.oauth2.TokenResult)8 TokenRequest (com.google.api.client.auth.oauth2.TokenRequest)7 GenericUrl (com.google.api.client.http.GenericUrl)6 OAuth2StrategyParameters (com.microsoft.identity.common.internal.providers.oauth2.OAuth2StrategyParameters)5 IOException (java.io.IOException)5 ClientException (com.microsoft.identity.common.exception.ClientException)4 MicrosoftTokenRequest (com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenRequest)4 RefreshTokenRequest (com.google.api.client.auth.oauth2.RefreshTokenRequest)3 TokenResponse (com.google.api.client.auth.oauth2.TokenResponse)3 MicrosoftStsOAuth2Configuration (com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Configuration)3 MicrosoftStsOAuth2Strategy (com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Strategy)3 Test (org.junit.Test)3 JsonWebSignature (com.google.api.client.json.webtoken.JsonWebSignature)2 JsonWebToken (com.google.api.client.json.webtoken.JsonWebToken)2 Beta (com.google.api.client.util.Beta)2 AzureActiveDirectoryAuthority (com.microsoft.identity.common.internal.authorities.AzureActiveDirectoryAuthority)2 HttpResponse (com.microsoft.identity.common.internal.net.HttpResponse)2 CertificateCredential (com.microsoft.identity.common.internal.providers.keys.CertificateCredential)2