Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Source SurveyMonkey: add OAuth support #7433

Merged
merged 3 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"sourceDefinitionId": "badc5925-0485-42be-8caa-b34096cb71b5",
"name": "Survey Monkey",
"dockerRepository": "airbyte/source-surveymonkey",
"dockerImageTag": "0.1.0",
"dockerImageTag": "0.1.2",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/surveymonkey"
}
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@
- name: Survey Monkey
sourceDefinitionId: badc5925-0485-42be-8caa-b34096cb71b5
dockerRepository: airbyte/source-surveymonkey
dockerImageTag: 0.1.0
dockerImageTag: 0.1.2
documentationUrl: https://docs.airbyte.io/integrations/sources/surveymonkey
sourceType: api
- name: Tempo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.1
LABEL io.airbyte.version=0.1.2
LABEL io.airbyte.name=airbyte/source-surveymonkey
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class SourceSurveymonkey(AbstractSource):
def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> Tuple[bool, Any]:
try:
authenticator = TokenAuthenticator(token=config["access_token"])
authenticator = self.get_authenticator(config)
start_date = pendulum.parse(config["start_date"])
stream = Surveys(authenticator=authenticator, start_date=start_date)
records = stream.read_records(sync_mode=SyncMode.full_refresh)
Expand All @@ -27,7 +27,17 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) ->
return False, repr(e)

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
authenticator = TokenAuthenticator(token=config["access_token"])
authenticator = self.get_authenticator(config)
start_date = pendulum.parse(config["start_date"])
args = {"authenticator": authenticator, "start_date": start_date}
return [Surveys(**args), SurveyPages(**args), SurveyQuestions(**args), SurveyResponses(**args)]

@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")

return TokenAuthenticator(token=token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems incorrect because we're not using the client ID and refresh token anywhere, could you provide more info on why that's the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sherifnada the SurveyMonkey does not provide a refresh token, only an access token which never expires. The Oauth2Authenticator class is not used here. In fact, OAuth in SurveyMonkey boils down to obtaining an access token in a different way than in the current implementation, the way of authentication remains the same

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"documentationUrl": "https://docs.airbyte.io/integrations/sources/surveymonkey",
"connectionSpecification": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "PostHog Spec",
"title": "SurveyMonkey Spec",
"type": "object",
"required": ["start_date", "access_token"],
"additionalProperties": false,
"required": ["start_date"],
"additionalProperties": true,
"properties": {
"start_date": {
"title": "Start Date",
Expand All @@ -14,11 +14,77 @@
"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"]
},
"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."
"credentials": {
"type": "object",
"title": "Authentication Type",
"oneOf": [
{
"title": "Authenticate via OAuth",
"type": "object",
"required": [
"client_id",
"client_secret",
"access_token",
"auth_type"
],
"properties": {
"auth_type": {
"type": "string",
"const": "OAuth",
"enum": ["OAuth"],
"default": "OAuth",
"order": 0
},
"client_id": {
"title": "Client ID",
"type": "string",
"description": "The Client ID of your developer application",
"airbyte_secret": true
},
"client_secret": {
"title": "Client Secret",
"type": "string",
"description": "The client secret of your developer application",
"airbyte_secret": true
},
"access_token": {
"title": "Access Token",
"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": {
"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."
}
}
}
]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're missing the authspecification node in the spec.
Take a look at the github source spec for an example.

}
},
"authSpecification": {
"auth_type": "oauth2.0",
"oauth2Specification": {
"rootObject": ["credentials", 0],
"oauthFlowInitParameters": [["client_id"], ["client_secret"]],
"oauthFlowOutputParameters": [["access_token"]]
}
}
}
1 change: 1 addition & 0 deletions docs/integrations/sources/surveymonkey.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Please read this [docs](https://developer.surveymonkey.com/api/v3/#getting-start

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.1.2 | 2021-10-27 | [7433](https://github.com/airbytehq/airbyte/pull/7433) | Add OAuth support |
| 0.1.1 | 2021-09-10 | [5983](https://github.com/airbytehq/airbyte/pull/5983) | Fix caching for gzip compressed http response |
| 0.1.0 | 2021-07-06 | [4097](https://github.com/airbytehq/airbyte/pull/4097) | Initial Release |