Search in sources :

Example 1 with AuthorizationCodeTokenRequest

use of com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest in project hub-alert by blackducksoftware.

the class AzureAuthorizationCodeFlow method newTokenRequest.

@Override
public AuthorizationCodeTokenRequest newTokenRequest(String authorizationCode) {
    AuthorizationCodeTokenRequest request = super.newTokenRequest(authorizationCode);
    request.setGrantType(AzureOAuthConstants.DEFAULT_GRANT_TYPE);
    request.setResponseClass(AzureTokenResponse.class);
    request.put(AzureOAuthConstants.REQUEST_BODY_FIELD_ASSERTION, authorizationCode);
    request.put(AzureOAuthConstants.REQUEST_BODY_FIELD_CLIENT_ASSERTION_TYPE, AzureOAuthConstants.DEFAULT_CLIENT_ASSERTION_TYPE);
    request.put(AzureOAuthConstants.REQUEST_BODY_FIELD_CLIENT_ASSERTION, clientSecret);
    request.put(AzureOAuthConstants.REQUEST_BODY_FIELD_REDIRECT_URI, redirectUri);
    return request;
}
Also used : AuthorizationCodeTokenRequest(com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)

Example 2 with AuthorizationCodeTokenRequest

use of com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest in project blackduck-alert by blackducksoftware.

the class AzureAuthorizationCodeFlow method newTokenRequest.

@Override
public AuthorizationCodeTokenRequest newTokenRequest(String authorizationCode) {
    AuthorizationCodeTokenRequest request = super.newTokenRequest(authorizationCode);
    request.setGrantType(AzureOAuthConstants.DEFAULT_GRANT_TYPE);
    request.setResponseClass(AzureTokenResponse.class);
    request.put(AzureOAuthConstants.REQUEST_BODY_FIELD_ASSERTION, authorizationCode);
    request.put(AzureOAuthConstants.REQUEST_BODY_FIELD_CLIENT_ASSERTION_TYPE, AzureOAuthConstants.DEFAULT_CLIENT_ASSERTION_TYPE);
    request.put(AzureOAuthConstants.REQUEST_BODY_FIELD_CLIENT_ASSERTION, clientSecret);
    request.put(AzureOAuthConstants.REQUEST_BODY_FIELD_REDIRECT_URI, redirectUri);
    return request;
}
Also used : AuthorizationCodeTokenRequest(com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)

Example 3 with AuthorizationCodeTokenRequest

use of com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest in project blackduck-alert by blackducksoftware.

the class AzureAuthorizationCodeFlowTest method builderTest.

@Test
public void builderTest() {
    AzureAuthorizationCodeFlow.Builder builder = new AzureAuthorizationCodeFlow.Builder(method, httpTransport, jsonFactory, genericUrl, clientAuthentication, clientId, authorizationServerEncodedUrl, null, null);
    assertNull(builder.getClientSecret());
    assertNull(builder.getRedirectUri());
    builder.setClientSecret(clientSecret);
    builder.setRedirectUri(redirectUri);
    assertEquals(clientSecret, builder.getClientSecret());
    assertEquals(redirectUri, builder.getRedirectUri());
    AuthorizationCodeFlow azureAuthorizationCodeFlow = builder.build();
    AuthorizationCodeTokenRequest tokenRequest = azureAuthorizationCodeFlow.newTokenRequest(authorizationCode);
    testAuthorizationCodeTokenRequest(tokenRequest);
}
Also used : AuthorizationCodeTokenRequest(com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow) Test(org.junit.jupiter.api.Test)

Example 4 with AuthorizationCodeTokenRequest

use of com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest in project blackduck-alert by blackducksoftware.

the class AzureAuthorizationCodeFlowTest method newTokenRequestTest.

@Test
public void newTokenRequestTest() {
    AzureAuthorizationCodeFlow azureAuthorizationCodeFlow = new AzureAuthorizationCodeFlow(method, httpTransport, jsonFactory, genericUrl, clientAuthentication, clientId, authorizationServerEncodedUrl, clientSecret, redirectUri);
    AuthorizationCodeTokenRequest tokenRequest = azureAuthorizationCodeFlow.newTokenRequest(authorizationCode);
    assertEquals(authorizationCode, tokenRequest.getCode());
    assertEquals(AzureOAuthConstants.DEFAULT_GRANT_TYPE, tokenRequest.getGrantType());
    assertEquals(redirectUri, tokenRequest.getRedirectUri());
    assertEquals("", tokenRequest.getScopes());
    assertEquals(authorizationCode, tokenRequest.get(AzureOAuthConstants.REQUEST_BODY_FIELD_ASSERTION));
    assertEquals(AzureOAuthConstants.DEFAULT_CLIENT_ASSERTION_TYPE, tokenRequest.get(AzureOAuthConstants.REQUEST_BODY_FIELD_CLIENT_ASSERTION_TYPE));
    assertEquals(clientSecret, tokenRequest.get(AzureOAuthConstants.REQUEST_BODY_FIELD_CLIENT_ASSERTION));
    assertEquals(redirectUri, tokenRequest.get(AzureOAuthConstants.REQUEST_BODY_FIELD_REDIRECT_URI));
}
Also used : AuthorizationCodeTokenRequest(com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest) Test(org.junit.jupiter.api.Test)

Example 5 with AuthorizationCodeTokenRequest

use of com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest in project hub-alert by blackducksoftware.

the class AzureBoardsProperties method requestTokens.

public Optional<Credential> requestTokens(AuthorizationCodeFlow authorizationCodeFlow, String authorizationCode) throws IOException {
    AuthorizationCodeTokenRequest tokenRequest = authorizationCodeFlow.newTokenRequest(authorizationCode);
    TokenResponse tokenResponse = tokenRequest.execute();
    Credential credential = authorizationCodeFlow.createAndStoreCredential(tokenResponse, oauthUserId);
    return Optional.ofNullable(credential);
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) StoredCredential(com.google.api.client.auth.oauth2.StoredCredential) TokenResponse(com.google.api.client.auth.oauth2.TokenResponse) AuthorizationCodeTokenRequest(com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)

Aggregations

AuthorizationCodeTokenRequest (com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)10 TokenResponse (com.google.api.client.auth.oauth2.TokenResponse)4 Test (org.junit.jupiter.api.Test)4 AuthorizationCodeFlow (com.google.api.client.auth.oauth2.AuthorizationCodeFlow)3 Credential (com.google.api.client.auth.oauth2.Credential)3 ClientParametersAuthentication (com.google.api.client.auth.oauth2.ClientParametersAuthentication)2 StoredCredential (com.google.api.client.auth.oauth2.StoredCredential)2 GenericUrl (com.google.api.client.http.GenericUrl)2 Builder (com.google.api.client.auth.oauth2.AuthorizationCodeFlow.Builder)1 IdToken (com.google.api.client.auth.openidconnect.IdToken)1 HttpRequest (com.google.api.client.http.HttpRequest)1 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 CodeExchangeException (uk.ac.cam.cl.dtg.segue.auth.exceptions.CodeExchangeException)1