Skip to content

Commit

Permalink
Fixes issue on cloud with redirect URI during token fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Weves committed Dec 12, 2024
1 parent 4ae3b48 commit 87d97d1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions backend/danswer/connectors/egnyte/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def oauth_authorization_url(cls, base_domain: str, state: str) -> str:
)

@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:
Expand All @@ -211,12 +211,13 @@ def oauth_code_to_token(cls, code: str) -> dict[str, Any]:

# 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"}
Expand Down
2 changes: 1 addition & 1 deletion backend/danswer/connectors/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def oauth_authorization_url(cls, base_domain: str, state: str) -> str:

@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


Expand Down
3 changes: 2 additions & 1 deletion backend/danswer/server/documents/standard_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 87d97d1

Please sign in to comment.