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

Changed client_secret to optional for token exchange methods; defaults to API Key now #337

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ nylas-python Changelog
v6.0.0b9
----------------
* Add support for sending drafts
* Changed `client_secret` to optional for token exchange methods; defaults to API Key now

v6.0.0b8
----------------
Expand Down
8 changes: 4 additions & 4 deletions nylas/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ class CodeExchangeRequest(TypedDict):
redirect_uri: Should match the same redirect URI that was used for getting the code during the initial authorization request.
code: OAuth 2.0 code fetched from the previous step.
client_id: Client ID of the application.
client_secret: Client secret of the application.
client_secret: Client secret of the application. If not provided, the API Key will be used instead.
code_verifier: The original plain text code verifier (code_challenge) used in the initial authorization request (PKCE).
"""

redirect_uri: str
code: str
client_id: str
client_secret: str
client_secret: NotRequired[str]
code_verifier: NotRequired[str]


Expand All @@ -80,13 +80,13 @@ class TokenExchangeRequest(TypedDict):
redirect_uri: Should match the same redirect URI that was used for getting the code during the initial authorization request.
refresh_token: Token to refresh/request your short-lived access token
client_id: Client ID of the application.
client_secret: Client secret of the application.
client_secret: Client secret of the application. If not provided, the API Key will be used instead.
"""

redirect_uri: str
refresh_token: str
client_id: str
client_secret: str
client_secret: NotRequired[str]


@dataclass_json
Expand Down
4 changes: 4 additions & 0 deletions nylas/resources/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def exchange_code_for_token(
Returns:
Information about the Nylas application
"""
if "client_secret" not in request:
request["client_secret"] = self._http_client.api_key

request_body = dict(request)
request_body["grant_type"] = "authorization_code"
Expand Down Expand Up @@ -122,6 +124,8 @@ def refresh_access_token(
Returns:
The response containing the new access token.
"""
if "client_secret" not in request:
request["client_secret"] = self._http_client.api_key

request_body = dict(request)
request_body["grant_type"] = "refresh_token"
Expand Down
Loading