From 71c5238fbbc258e4ad0f987f8b96fcc3a67bb78b Mon Sep 17 00:00:00 2001 From: Sergey Chvalyuk Date: Tue, 2 Nov 2021 23:10:51 +0200 Subject: [PATCH] YouTubeAnalyticsOAuthFlow added Signed-off-by: Sergey Chvalyuk --- .../oauth/OAuthImplementationFactory.java | 2 + .../google/YouTubeAnalyticsOAuthFlow.java | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 airbyte-oauth/src/main/java/io/airbyte/oauth/flows/google/YouTubeAnalyticsOAuthFlow.java diff --git a/airbyte-oauth/src/main/java/io/airbyte/oauth/OAuthImplementationFactory.java b/airbyte-oauth/src/main/java/io/airbyte/oauth/OAuthImplementationFactory.java index f9f450c286d5..a67e83215bb6 100644 --- a/airbyte-oauth/src/main/java/io/airbyte/oauth/OAuthImplementationFactory.java +++ b/airbyte-oauth/src/main/java/io/airbyte/oauth/OAuthImplementationFactory.java @@ -18,6 +18,7 @@ import io.airbyte.oauth.flows.google.GoogleAnalyticsOAuthFlow; import io.airbyte.oauth.flows.google.GoogleSearchConsoleOAuthFlow; import io.airbyte.oauth.flows.google.GoogleSheetsOAuthFlow; +import io.airbyte.oauth.flows.google.YouTubeAnalyticsOAuthFlow; import java.util.Map; import java.util.UUID; @@ -39,6 +40,7 @@ public OAuthImplementationFactory(final ConfigRepository configRepository) { .put("airbyte/source-salesforce", new SalesforceOAuthFlow(configRepository)) .put("airbyte/source-surveymonkey", new SurveymonkeyOAuthFlow(configRepository)) .put("airbyte/source-trello", new TrelloOAuthFlow(configRepository)) + .put("airbyte/source-youtube-analytics", new YouTubeAnalyticsOAuthFlow(configRepository)) .build(); } diff --git a/airbyte-oauth/src/main/java/io/airbyte/oauth/flows/google/YouTubeAnalyticsOAuthFlow.java b/airbyte-oauth/src/main/java/io/airbyte/oauth/flows/google/YouTubeAnalyticsOAuthFlow.java new file mode 100644 index 000000000000..92631330a084 --- /dev/null +++ b/airbyte-oauth/src/main/java/io/airbyte/oauth/flows/google/YouTubeAnalyticsOAuthFlow.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.oauth.flows.google; + +import com.fasterxml.jackson.databind.JsonNode; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import io.airbyte.config.persistence.ConfigRepository; +import java.net.http.HttpClient; +import java.util.function.Supplier; + +public class YouTubeAnalyticsOAuthFlow extends GoogleOAuthFlow { + + public static final String SCOPE_URL = "https://www.googleapis.com/auth/yt-analytics.readonly"; + + public YouTubeAnalyticsOAuthFlow(final ConfigRepository configRepository) { + super(configRepository); + } + + @VisibleForTesting + YouTubeAnalyticsOAuthFlow(final ConfigRepository configRepository, final HttpClient httpClient, final Supplier stateSupplier) { + super(configRepository, httpClient, stateSupplier); + } + + @Override + protected String getScope() { + return SCOPE_URL; + } + + @Override + protected String getClientIdUnsafe(final JsonNode config) { + // the config object containing client ID and secret is nested inside the "credentials" object + Preconditions.checkArgument(config.hasNonNull("credentials")); + return super.getClientIdUnsafe(config.get("credentials")); + } + + @Override + protected String getClientSecretUnsafe(final JsonNode config) { + // the config object containing client ID and secret is nested inside the "credentials" object + Preconditions.checkArgument(config.hasNonNull("credentials")); + return super.getClientSecretUnsafe(config.get("credentials")); + } + +}