Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Rezchykov committed Nov 2, 2021
1 parent 5dceb6b commit 99878af
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,5 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:

@staticmethod
def get_authenticator(config: Mapping[str, Any]):
# backward compatibility
if config.get("access_token"):
token = config.get("access_token")
else:
token = config.get("credentials", {}).get("access_token")

token = config["access_token"]
return TokenAuthenticator(token=token)
Original file line number Diff line number Diff line change
Expand Up @@ -14,61 +14,18 @@
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z?$",
"examples": ["2021-01-01T00:00:00Z"]
},
"credentials": {
"type": "object",
"title": "Authentication Type",
"description": "Authenticate over oAuth flow or provide token",
"oneOf": [
{
"title": "Authenticate via OAuth",
"type": "object",
"required": ["access_token", "auth_type"],
"properties": {
"auth_type": {
"type": "string",
"const": "OAuth",
"enum": ["OAuth"],
"default": "OAuth",
"order": 0
},
"access_token": {
"title": "Access Token",
"description": "",
"type": "string",
"description": "An access token generated using the above client ID and secret",
"airbyte_secret": true
}
}
},
{
"type": "object",
"title": "Token Authentication",
"additionalProperties": false,
"required": ["access_token", "auth_type"],
"properties": {
"auth_type": {
"type": "string",
"const": "Token",
"enum": ["Token"],
"default": "Token",
"order": 0
},
"access_token": {
"title": "Access Token",
"type": "string",
"airbyte_secret": true,
"description": "API Token. See the <a href=\"https://docs.airbyte.io/integrations/sources/surveymonkey\">docs</a> for information on how to generate this key."
}
}
}
]
"access_token": {
"title": "Access Token",
"type": "string",
"airbyte_secret": true,
"description": "API Token. See the <a href=\"https://docs.airbyte.io/integrations/sources/surveymonkey\">docs</a> for information on how to generate this key."
}
}
},
"authSpecification": {
"auth_type": "oauth2.0",
"oauth2Specification": {
"rootObject": ["credentials", 0],
"rootObject": [],
"oauthFlowInitParameters": [],
"oauthFlowOutputParameters": [["access_token"]]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

package io.airbyte.oauth.flows;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import io.airbyte.config.persistence.ConfigRepository;
import com.google.common.base.Preconditions;
import io.airbyte.oauth.BaseOAuthFlow;
import java.io.IOException;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -60,4 +62,10 @@ protected Map<String, String> getAccessTokenQueryParameters(String clientId, Str
.build();
}

@Override
protected Map<String, Object> extractRefreshToken(final JsonNode data, String accessTokenUrl) throws IOException {
Preconditions.checkArgument(data.has("access_token"), "Missing 'access_token' in query params from %s", ACCESS_TOKEN_URL);
return Map.of("access_token", data.get("access_token").asText());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ public void testFullSurveymonkeyOAuthFlow() throws InterruptedException, ConfigN
final Map<String, Object> params = flow.completeSourceOAuth(workspaceId, definitionId,
Map.of("code", serverHandler.getParamValue()), REDIRECT_URL);
LOGGER.info("Response from completing OAuth Flow is: {}", params.toString());
assertTrue(params.containsKey("credentials"));
final Map<String, Object> credentials = (Map<String, Object>) params.get("credentials");
assertTrue(credentials.containsKey("access_token"));
assertTrue(credentials.get("access_token").toString().length() > 0);
assertTrue(params.containsKey("access_token"));
assertTrue(params.get("access_token").toString().length() > 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void testCompleteSourceOAuth() throws IOException, InterruptedException,
final Map<String, Object> actualQueryParams =
surveymonkeyOAuthFlow.completeSourceOAuth(workspaceId, definitionId, queryParams, REDIRECT_URL);

assertEquals(Jsons.serialize(Map.of("credentials", returnedCredentials)), Jsons.serialize(actualQueryParams));
assertEquals(returnedCredentials, actualQueryParams);
}

@Test
Expand All @@ -109,7 +109,7 @@ public void testCompleteDestinationOAuth() throws IOException, ConfigNotFoundExc
final Map<String, Object> actualQueryParams =
surveymonkeyOAuthFlow.completeDestinationOAuth(workspaceId, definitionId, queryParams, REDIRECT_URL);

assertEquals(Jsons.serialize(Map.of("credentials", returnedCredentials)), Jsons.serialize(actualQueryParams));
assertEquals(returnedCredentials, actualQueryParams);
}

}

0 comments on commit 99878af

Please sign in to comment.