From fd643d5e7bf97dbf12486259109feed25703d5af Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:59:56 -0400 Subject: [PATCH] Fix KeyError when building Auth URL (#284) We were not properly checking the existence of an entry in a dict. --- nylas/models/auth.py | 1 + nylas/resources/auth.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/nylas/models/auth.py b/nylas/models/auth.py index 29ef0a1a..dca5dba5 100644 --- a/nylas/models/auth.py +++ b/nylas/models/auth.py @@ -107,6 +107,7 @@ class CodeExchangeResponse: access_token: str grant_id: str + email: str scope: str expires_in: int refresh_token: Optional[str] = None diff --git a/nylas/resources/auth.py b/nylas/resources/auth.py index 37d5c013..2c6a90a9 100644 --- a/nylas/resources/auth.py +++ b/nylas/resources/auth.py @@ -27,10 +27,10 @@ def _hash_pkce_secret(secret: str) -> str: def _build_query(config: dict) -> dict: config["response_type"] = "code" - if not config["access_type"]: + if "access_type" not in config: config["access_type"] = "online" - if config["scope"]: + if "scope" in config: config["scope"] = " ".join(config["scope"]) return config @@ -49,7 +49,9 @@ def _build_query_with_admin_consent(config: dict) -> dict: params = _build_query(config) params["response_type"] = "adminconsent" - params["credential_id"] = config["credentialId"] + + if "credential_id" in config: + params["credential_id"] = config["credential_id"] return params