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 Zendesk-Chat: add oauth flow support #7313

Merged
merged 29 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0eb073f
added oauth support
bazarnov Oct 20, 2021
5d3077d
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Oct 21, 2021
2182be8
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Oct 22, 2021
2e95066
added java part of oauth
bazarnov Oct 22, 2021
f292b68
changed spec.json to have credentials nested object
bazarnov Oct 23, 2021
dac667e
corrected oauthFlow.java
bazarnov Oct 23, 2021
a1118be
added title to start date in spec.json
bazarnov Oct 24, 2021
3f2eeba
small corrections to OAuthFlow.java
bazarnov Oct 24, 2021
d8bb699
added changelog
bazarnov Oct 24, 2021
2dd3c85
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Oct 28, 2021
afd16be
updated after review
bazarnov Oct 28, 2021
e6abf76
add new secret to workflows
bazarnov Oct 28, 2021
0ed2e1d
formated
bazarnov Oct 28, 2021
d955b0a
fixed conflicts
bazarnov Oct 29, 2021
2ecdcc4
updated after review
bazarnov Nov 1, 2021
4620788
updated after review
bazarnov Nov 1, 2021
ed61026
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Nov 1, 2021
8b025ab
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Nov 1, 2021
cf68d5e
fixed spec.json for SAT
bazarnov Nov 1, 2021
0e17ead
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Dec 15, 2021
1cc691a
made up java-part
bazarnov Dec 16, 2021
e34524f
added java test
bazarnov Dec 16, 2021
a80bd88
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Dec 22, 2021
c4a6e62
updated
bazarnov Dec 22, 2021
c24187c
merged with PR https://github.com/airbytehq/airbyte/pull/9040
bazarnov Dec 22, 2021
a3d07e8
Merge remote-tracking branch 'origin/master' into bazarnov/zd-chat-oauth
bazarnov Dec 23, 2021
fcb19e0
added old config test in SAT
bazarnov Dec 23, 2021
b8a5abd
bumped version
bazarnov Dec 23, 2021
8d4a37c
new spec generated
bazarnov Dec 23, 2021
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,7 +2,7 @@
"sourceDefinitionId": "40d24d0f-b8f9-4fe0-9e6c-b06c0f3f45e4",
"name": "Zendesk Chat",
"dockerRepository": "airbyte/source-zendesk-chat",
"dockerImageTag": "0.1.2",
"dockerImageTag": "0.1.3",
"documentationUrl": "https://docs.airbyte.io/integrations/sources/zendesk-chat",
"icon": "zendesk.svg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
- sourceDefinitionId: 40d24d0f-b8f9-4fe0-9e6c-b06c0f3f45e4
name: Zendesk Chat
dockerRepository: airbyte/source-zendesk-chat
dockerImageTag: 0.1.2
dockerImageTag: 0.1.3
documentationUrl: https://docs.airbyte.io/integrations/sources/zendesk-chat
icon: zendesk.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ RUN pip install .

ENV AIRBYTE_ENTRYPOINT "/airbyte/base.sh"

LABEL io.airbyte.version=0.1.2
LABEL io.airbyte.version=0.1.3
LABEL io.airbyte.name=airbyte/source-zendesk-chat
10 changes: 10 additions & 0 deletions airbyte-integrations/connectors/source-zendesk-chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ python main_dev.py discover --config secrets/config.json
python main_dev.py read --config secrets/config.json --catalog sample_files/configured_catalog.json
```

#### Acceptance Tests
Customize `acceptance-test-config.yml` file to configure tests. See [Source Acceptance Tests](https://docs.airbyte.io/connector-development/testing-connectors/source-acceptance-tests-reference) for more information.
If your connector requires to create or destroy resources for use during acceptance tests create fixtures for it and place them inside integration_tests/acceptance.py.
To run your integration tests with acceptance tests, from the connector root, run
```
docker build . --no-cache -t airbyte/source-zendesk-chat:dev \
&& python -m pytest -p source_acceptance_test.plugin
```
To run your integration tests with docker

### Unit Tests
To run unit tests locally, from the connector directory run:
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"start_date": "2020-10-01T00:00:00Z",
"credentials": {
"access_token": "wrongkey-access-token",
"start_date": "2020-12-12T00:00:00Z"
}
"credentials": "access_token",
"access_token": "wrong_access_token"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
class SourceZendeskChat(AbstractSource):
def check_connection(self, logger, config) -> Tuple[bool, any]:
try:
authenticator = TokenAuthenticator(token=config["access_token"])
authenticator = TokenAuthenticator(token=config["credentials"]["access_token"])
list(RoutingSettings(authenticator=authenticator).read_records(SyncMode.full_refresh))
return True, None
except Exception as error:
return False, f"Unable to connect to Zendesk Chat API with the provided credentials - {error}"
bazarnov marked this conversation as resolved.
Show resolved Hide resolved

def streams(self, config: Mapping[str, Any]) -> List[Stream]:
authenticator = TokenAuthenticator(token=config["access_token"])
authenticator = TokenAuthenticator(token=config["credentials"]["access_token"])
return [
Agents(authenticator=authenticator),
AgentTimelines(authenticator=authenticator, start_date=config["start_date"]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,82 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Zendesk Chat Spec",
"type": "object",
"required": ["start_date", "access_token"],
"required": ["start_date", "credentials"],
bazarnov marked this conversation as resolved.
Show resolved Hide resolved
"additionalProperties": false,
"properties": {
"start_date": {
"type": "string",
"title": "Start Date",
"description": "The date from which you'd like to replicate data for Zendesk Chat API, in the format YYYY-MM-DDT00:00:00Z.",
"examples": ["2021-02-01T00:00:00Z"],
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
},
"access_token": {
"type": "string",
"description": "The value of the Access Token generated. See the <a href=\"https://docs.airbyte.io/integrations/sources/zendesk-chat\">docs</a> for more information",
"airbyte_secret": true
"credentials": {
"title": "Authorization Method",
"type": "object",
"oneOf": [
{
"type": "object",
"title": "OAuth2.0",
"required": ["credentials"],
"properties": {
"credentials": {
"type": "string",
"const": "oauth2.0",
"enum": ["oauth2"],
"default": "oauth2",
"order": 0
},
"client_id": {
"type": "string",
"title": "Client ID",
"description": "The Client ID of your OAuth application",
"airbyte_secret": true
},
"client_secret": {
"type": "string",
"title": "Client Secret",
"description": "The Client Secret of your OAuth application.",
"airbyte_secret": true
},
"access_token": {
"type": "string",
"title": "Access Token",
"description": "Access Token for making authenticated requests.",
"airbyte_secret": true
}
}
},
{
"type": "object",
"title": "Access Token",
"required": ["credentials"],
"properties": {
"credentials": {
bazarnov marked this conversation as resolved.
Show resolved Hide resolved
"type": "string",
"const": "access_token",
"enum": ["access_token"],
"default": "access_token",
"order": 0
},
"access_token": {
"type": "string",
"title": "Access Token",
"description": "The Access Token to make authenticated requests.",
"airbyte_secret": true
}
}
bazarnov marked this conversation as resolved.
Show resolved Hide resolved
}
]
}
}
},
"authSpecification": {
"auth_type": "oauth2.0",
"oauth2Specification": {
"rootObject": ["credentials", "0"],
"oauthFlowInitParameters": [["client_id"], ["client_secret"]],
"oauthFlowOutputParameters": [["access_token"]]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,5 @@
#


"""
MIT License

Copyright (c) 2020 Airbyte

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

# format anchor


def test_example_method():
assert True
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.airbyte.oauth.flows.GithubOAuthFlow;
import io.airbyte.oauth.flows.SalesforceOAuthFlow;
import io.airbyte.oauth.flows.TrelloOAuthFlow;
import io.airbyte.oauth.flows.ZendeskChatOAuthFlow;
import io.airbyte.oauth.flows.google.GoogleAdsOAuthFlow;
import io.airbyte.oauth.flows.google.GoogleAnalyticsOAuthFlow;
import io.airbyte.oauth.flows.google.GoogleSearchConsoleOAuthFlow;
Expand All @@ -33,6 +34,7 @@ public OAuthImplementationFactory(final ConfigRepository configRepository) {
.put("airbyte/source-google-sheets", new GoogleSheetsOAuthFlow(configRepository))
.put("airbyte/source-salesforce", new SalesforceOAuthFlow(configRepository))
.put("airbyte/source-trello", new TrelloOAuthFlow(configRepository))
.put("airbyte/source-zendesk-chat", new ZendeskChatOAuthFlow(configRepository))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (c) 2021 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.oauth.flows;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.oauth.BaseOAuthFlow;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.util.Map;
import java.util.UUID;
import java.util.function.Supplier;
import org.apache.http.client.utils.URIBuilder;

/**
* Following docs from https://developer.zendesk.com/documentation/live-chat/getting-started/auth/
*/
public class ZendeskChatOAuthFlow extends BaseOAuthFlow {

private static final String ACCESS_TOKEN_URL = "https://www.zopim.com/oauth2/token";

public ZendeskChatOAuthFlow(final ConfigRepository configRepository) {
super(configRepository);
}

@VisibleForTesting
ZendeskChatOAuthFlow(final ConfigRepository configRepository, final HttpClient httpClient, final Supplier<String> stateSupplier) {
super(configRepository, httpClient, stateSupplier);
}

@Override
protected String formatConsentUrl(final UUID definitionId, final String clientId, final String redirectUrl) throws IOException {
final URIBuilder builder = new URIBuilder()
.setScheme("https")
.setHost("www.zopim.com")
.setPath("oauth2/authorizations/new")
// required
.addParameter("client_id", clientId)
.addParameter("redirect_uri", redirectUrl)
.addParameter("response_type", "code")
.addParameter("scope", "read%20chat")
.addParameter("state", getState());
try {
return builder.build().toString();
} catch (final URISyntaxException e) {
throw new IOException("Failed to format Consent URL for OAuth flow", e);
}
}

@Override
protected String getClientIdUnsafe(JsonNode config) {
// the config object containing client ID is nested inside the "credentials" object
Preconditions.checkArgument(config.hasNonNull("credentials"));
return super.getClientIdUnsafe(config.get("credentials"));
}

@Override
protected String getClientSecretUnsafe(JsonNode config) {
// the config object containing client SECRET is nested inside the "credentials" object
Preconditions.checkArgument(config.hasNonNull("credentials"));
return super.getClientSecretUnsafe(config.get("credentials"));
}

@Override
protected String getAccessTokenUrl() {
return ACCESS_TOKEN_URL;
}

@Override
protected Map<String, String> getAccessTokenQueryParameters(String clientId, String clientSecret, String authCode, String redirectUrl) {
return ImmutableMap.<String, String>builder()
// required
.put("grant_type", "authorization_code")
.put("code", authCode)
.put("client_id", clientId)
.put("client_secret", clientSecret)
.put("redirect_uri", redirectUrl)
.put("scope", "read")
.build();
}

@Override
protected Map<String, Object> extractRefreshToken(final JsonNode data, String accessTokenUrl) throws IOException {
// the config object containing access_token is nested inside the "credentials" object
if (data.has("access_token")) {
return Map.of("credentials", Map.of("access_token", data.get("access_token").asText()));
} else {
throw new IOException(String.format("Missing 'access_token' in query params from %s", ACCESS_TOKEN_URL));
}
}

}
11 changes: 11 additions & 0 deletions docs/integrations/sources/zendesk-chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ The Zendesk connector should not run into Zendesk API limitations under normal u

* Zendesk Chat Access Token

### Connect using `OAuth 2.0` option:
1. Select `OAuth2.0` in `Authorization Method`
2. Click on `authenticate your Zendesk Chat account`
2. Proceed the authentication using your credentials for your Zendesk account.

### Connect using `Access Token` option:
1. Generate a Access Token as described in [Zendesk Chat docs](https://developer.zendesk.com/rest_api/docs/chat/auth)
2. Use the generated `access_token` in Airbyte connection.


### Setup guide

Generate a Access Token as described in [Zendesk Chat docs](https://developer.zendesk.com/rest_api/docs/chat/auth)
Expand All @@ -62,6 +72,7 @@ We recommend creating a restricted, read-only key specifically for Airbyte acces

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.1.3 | 2021-10-22 | []() | Added support of `OAuth 2.0` authentication |
| 0.1.2 | 2021-08-17 | [5476](https://github.com/airbytehq/airbyte/pull/5476) | Correct field unread to boolean type |
| 0.1.1 | 2021-06-09 | [3973](https://github.com/airbytehq/airbyte/pull/3973) | Add `AIRBYTE_ENTRYPOINT` for Kubernetes support |
| 0.1.0 | 2021-05-03 | [3088](https://github.com/airbytehq/airbyte/pull/3088) | Initial release |
Expand Down