Search in sources :

Example 56 with TokenResponse

use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse in project microsoft-authentication-library-common-for-android by AzureAD.

the class ObjectMapperTest method test_JsonToObjectMSResponseNumbersAndStuff.

// Here we're leaving off everything that isn't a string, for now.
@Test
public void test_JsonToObjectMSResponseNumbersAndStuff() {
    TokenResponse tr = ObjectMapper.deserializeJsonStringToObject(JSON_TOKEN_REQUEST_OTHER_VALUE, TokenResponse.class);
    Assert.assertEquals("idtokenval", tr.getIdToken());
    final Iterator<Map.Entry<String, String>> iterator = tr.getExtraParameters().iterator();
    Map.Entry<String, String> param = iterator.next();
    Assert.assertEquals("client_id", param.getKey());
    Assert.assertEquals(CLIENT_ID, param.getValue());
    Assert.assertFalse(iterator.hasNext());
}
Also used : TokenResponse(com.microsoft.identity.common.internal.providers.oauth2.TokenResponse) MicrosoftTokenResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenResponse) Map(java.util.Map) Test(org.junit.Test)

Example 57 with TokenResponse

use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse in project microsoft-authentication-library-common-for-android by AzureAD.

the class ObjectMapperTest method test_JsonToObjectMSResponse.

@Test
public void test_JsonToObjectMSResponse() {
    TokenResponse tr = ObjectMapper.deserializeJsonStringToObject(JSON_TOKEN_REQUEST, TokenResponse.class);
    Assert.assertEquals("idtokenval", tr.getIdToken());
    final Iterator<Map.Entry<String, String>> iterator = tr.getExtraParameters().iterator();
    Map.Entry<String, String> param = iterator.next();
    Assert.assertEquals("client_id", param.getKey());
    Assert.assertEquals(CLIENT_ID, param.getValue());
    param = iterator.next();
    Assert.assertEquals("other_param", param.getKey());
    Assert.assertEquals("other_value", param.getValue());
    Assert.assertFalse(iterator.hasNext());
}
Also used : TokenResponse(com.microsoft.identity.common.internal.providers.oauth2.TokenResponse) MicrosoftTokenResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenResponse) Map(java.util.Map) Test(org.junit.Test)

Example 58 with TokenResponse

use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse in project microsoft-authentication-library-common-for-android by AzureAD.

the class ObjectMapperTest method test_JsonToObjectMSResponseArray.

@Test(expected = JsonParseException.class)
public void test_JsonToObjectMSResponseArray() {
    TokenResponse tr = ObjectMapper.deserializeJsonStringToObject(JSON_TOKEN_REQUEST_ARRAY, TokenResponse.class);
    Assert.assertEquals("idtokenval", tr.getIdToken());
    final Iterator<Map.Entry<String, String>> iterator = tr.getExtraParameters().iterator();
    Map.Entry<String, String> param = iterator.next();
    Assert.assertEquals("client_id", param.getKey());
    Assert.assertEquals(CLIENT_ID, param.getValue());
    param = iterator.next();
    Assert.assertEquals("other_param", param.getKey());
    Assert.assertEquals("other_value", param.getValue());
    Assert.assertFalse(iterator.hasNext());
}
Also used : TokenResponse(com.microsoft.identity.common.internal.providers.oauth2.TokenResponse) MicrosoftTokenResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenResponse) Map(java.util.Map) Test(org.junit.Test)

Example 59 with TokenResponse

use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse in project microsoft-authentication-library-common-for-android by AzureAD.

the class MockDelayedResponseStrategy method getTokenResult.

public TokenResult getTokenResult() {
    final TokenResponse tokenResponse = MockTokenResponse.getMockSuccessTokenResponse();
    final TokenResult tokenResult = new TokenResult(tokenResponse);
    return tokenResult;
}
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)

Example 60 with TokenResponse

use of com.microsoft.identity.common.internal.providers.oauth2.TokenResponse 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

TokenResponse (com.google.api.client.auth.oauth2.TokenResponse)48 IOException (java.io.IOException)23 GenericUrl (com.google.api.client.http.GenericUrl)22 Credential (com.google.api.client.auth.oauth2.Credential)20 ClientParametersAuthentication (com.google.api.client.auth.oauth2.ClientParametersAuthentication)16 AuthorizationCodeFlow (com.google.api.client.auth.oauth2.AuthorizationCodeFlow)15 Map (java.util.Map)13 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)12 TokenResponse (com.microsoft.identity.common.internal.providers.oauth2.TokenResponse)11 BearerToken (com.google.api.client.auth.oauth2.BearerToken)9 TokenResult (com.microsoft.identity.common.internal.providers.oauth2.TokenResult)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 Test (org.junit.Test)7 URL (java.net.URL)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Timed (com.codahale.metrics.annotation.Timed)5 AuthorizationCodeRequestUrl (com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl)5 Collections (java.util.Collections)5