Fixes issue on cloud with redirect URI during token fetching

This commit is contained in:
Weves
2024-12-12 12:25:39 -08:00
committed by Chris Weaver
parent 4ae3b48938
commit 87d97d13d5
3 changed files with 6 additions and 4 deletions

View File

@@ -201,7 +201,7 @@ class EgnyteConnector(LoadConnector, PollConnector, OAuthConnector):
)
@classmethod
def oauth_code_to_token(cls, code: str) -> dict[str, Any]:
def oauth_code_to_token(cls, base_domain: str, code: str) -> dict[str, Any]:
if not EGNYTE_CLIENT_ID:
raise ValueError("EGNYTE_CLIENT_ID environment variable must be set")
if not EGNYTE_CLIENT_SECRET:
@@ -211,12 +211,13 @@ class EgnyteConnector(LoadConnector, PollConnector, OAuthConnector):
# Exchange code for token
url = f"https://{EGNYTE_BASE_DOMAIN}.egnyte.com/puboauth/token"
redirect_uri = f"{EGNYTE_LOCALHOST_OVERRIDE or base_domain}/connector/oauth/callback/egnyte"
data = {
"client_id": EGNYTE_CLIENT_ID,
"client_secret": EGNYTE_CLIENT_SECRET,
"code": code,
"grant_type": "authorization_code",
"redirect_uri": f"{EGNYTE_LOCALHOST_OVERRIDE or ''}/connector/oauth/callback/egnyte",
"redirect_uri": redirect_uri,
"scope": "Egnyte.filesystem",
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}

View File

@@ -78,7 +78,7 @@ class OAuthConnector(BaseConnector):
@classmethod
@abc.abstractmethod
def oauth_code_to_token(cls, code: str) -> dict[str, Any]:
def oauth_code_to_token(cls, base_domain: str, code: str) -> dict[str, Any]:
raise NotImplementedError

View File

@@ -117,7 +117,8 @@ def oauth_callback(
raise HTTPException(status_code=400, detail="Invalid OAuth state")
original_url = original_url_bytes.decode("utf-8")
token_info = connector_cls.oauth_code_to_token(code)
base_url = WEB_DOMAIN
token_info = connector_cls.oauth_code_to_token(base_url, code)
# Create a new credential with the token info
credential_data = CredentialBase(