forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 Source Shopify: support oauth flow (airbytehq#6951)
- Loading branch information
Showing
13 changed files
with
142 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
airbyte-integrations/connectors/source-shopify/integration_tests/invalid_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"shop": "SHOP_NAME", | ||
"start_date": "2020-11-01", | ||
"api_password": "API_PASSWORD" | ||
} | ||
"auth_method": { | ||
"auth_method": "api_password", | ||
"api_password": "SOME_API_PASSWORD" | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
airbyte-integrations/connectors/source-shopify/integration_tests/invalid_oauth_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"shop": "SHOP_NAME", | ||
"start_date": "2020-11-01", | ||
"auth_method": { | ||
"auth_method": "access_token", | ||
"client_id": "SOME_CLIENT_ID", | ||
"client_secret": "SOME_CLIENT_SECRET", | ||
"access_token": "SOME_ACCESS_TOKEN" | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
airbyte-integrations/connectors/source-shopify/source_shopify/auth.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
# | ||
|
||
from typing import Any, Dict, Mapping | ||
|
||
from airbyte_cdk import AirbyteLogger | ||
from airbyte_cdk.sources.streams.http.requests_native_auth import TokenAuthenticator | ||
|
||
|
||
class NotImplementedAuth(Exception): | ||
""" Not implemented Auth option error""" | ||
|
||
logger = AirbyteLogger() | ||
|
||
def __init__(self, auth_method: str = None): | ||
self.message = f"Not implemented Auth method = {auth_method}" | ||
super().__init__(self.logger.error(self.message)) | ||
|
||
|
||
class ShopifyAuthenticator(TokenAuthenticator): | ||
|
||
""" | ||
Making Authenticator to be able to accept Header-Based authentication. | ||
""" | ||
|
||
def __init__(self, config: Mapping[str, Any]): | ||
self.config = config | ||
|
||
def get_auth_header(self) -> Mapping[str, Any]: | ||
|
||
auth_header: str = "X-Shopify-Access-Token" | ||
auth_method: Dict = self.config["auth_method"] | ||
auth_option: str = auth_method.get("auth_method") | ||
|
||
if auth_option == "access_token": | ||
return {auth_header: auth_method.get("access_token")} | ||
elif auth_option == "api_password": | ||
return {auth_header: auth_method.get("api_password")} | ||
else: | ||
raise NotImplementedAuth(auth_option) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters