Search in sources :

Example 11 with AuthorizationCodeFlow

use of com.google.api.client.auth.oauth2.AuthorizationCodeFlow in project hub-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 12 with AuthorizationCodeFlow

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

the class AzureBoardsProperties method createAzureHttpService.

public AzureHttpService createAzureHttpService(ProxyInfo proxy, Gson gson, String authorizationCode) throws AlertException {
    HttpTransport httpTransport = createHttpTransport(proxy);
    try {
        AuthorizationCodeFlow oAuthFlow = createOAuthFlow(httpTransport);
        Credential oAuthCredential = requestTokens(oAuthFlow, authorizationCode).orElseThrow(() -> new AlertException(String.format("Cannot request Azure OAuth credential associated with '%s'", oauthUserId)));
        AzureHttpRequestCreator httpRequestCreator = AzureHttpRequestCreatorFactory.withCredential(httpTransport, oAuthCredential, gson);
        return new AzureHttpService(gson, httpRequestCreator);
    } catch (IOException e) {
        throw new AlertException("Cannot request OAuth credentials", e);
    }
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) ApacheHttpTransport(com.google.api.client.http.apache.v2.ApacheHttpTransport) Credential(com.google.api.client.auth.oauth2.Credential) StoredCredential(com.google.api.client.auth.oauth2.StoredCredential) AzureHttpRequestCreator(com.synopsys.integration.azure.boards.common.http.AzureHttpRequestCreator) IOException(java.io.IOException) AzureHttpService(com.synopsys.integration.azure.boards.common.http.AzureHttpService) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow) AzureAuthorizationCodeFlow(com.synopsys.integration.azure.boards.common.oauth.AzureAuthorizationCodeFlow)

Example 13 with AuthorizationCodeFlow

use of com.google.api.client.auth.oauth2.AuthorizationCodeFlow in project community by GoogleCloudPlatform.

the class SimpleExample method authorize.

private Credential authorize() throws Exception {
    HttpExecuteInterceptor credentials = new ClientParametersAuthentication(this.clientId, this.clientSecret);
    AuthorizationCodeFlow flow = new AuthorizationCodeFlow.Builder(authorizationHeaderAccessMethod(), httpTransport, jsonFactory, new GenericUrl(TOKEN_SERVER_URL), credentials, this.clientId, AUTHORIZATION_SERVER_URL).setScopes(SCOPES).setDataStoreFactory(dataStoreFactory).build();
    LocalServerReceiver.Builder builder = new LocalServerReceiver.Builder();
    VerificationCodeReceiver receiver = builder.setHost(DOMAIN).setPort(PORT).build();
    return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
Also used : ClientParametersAuthentication(com.google.api.client.auth.oauth2.ClientParametersAuthentication) VerificationCodeReceiver(com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver) AuthorizationCodeInstalledApp(com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp) LocalServerReceiver(com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver) AuthorizationCodeFlow(com.google.api.client.auth.oauth2.AuthorizationCodeFlow)

Aggregations

AuthorizationCodeFlow (com.google.api.client.auth.oauth2.AuthorizationCodeFlow)12 Credential (com.google.api.client.auth.oauth2.Credential)10 IOException (java.io.IOException)6 TokenResponse (com.google.api.client.auth.oauth2.TokenResponse)5 ClientParametersAuthentication (com.google.api.client.auth.oauth2.ClientParametersAuthentication)4 StoredCredential (com.google.api.client.auth.oauth2.StoredCredential)4 VerificationCodeReceiver (com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver)3 LocalServerReceiver (com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver)3 GenericUrl (com.google.api.client.http.GenericUrl)3 HttpTransport (com.google.api.client.http.HttpTransport)3 ApacheHttpTransport (com.google.api.client.http.apache.v2.ApacheHttpTransport)3 AzureAuthorizationCodeFlow (com.synopsys.integration.azure.boards.common.oauth.AzureAuthorizationCodeFlow)3 AuthorizationCodeTokenRequest (com.google.api.client.auth.oauth2.AuthorizationCodeTokenRequest)2 AuthorizationCodeInstalledApp (com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp)2 GoogleAuthorizationCodeFlow (com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 AuthorizationCodeInstalledAppSecureOverride (org.dataportabilityproject.shared.auth.AuthorizationCodeInstalledAppSecureOverride)2 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 AzureHttpRequestCreator (com.synopsys.integration.azure.boards.common.http.AzureHttpRequestCreator)1