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

Fixes issue on cloud with Egnyte redirect URI during token fetching #3451

Merged
merged 1 commit into from
Dec 12, 2024
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
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
Loading