Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
nylas-python Changelog
======================
Unreleased
----------
* UAS multi-credential update

v6.14.2
----------
Expand Down
1 change: 1 addition & 0 deletions nylas/models/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class URLForAuthenticationConfig(TypedDict):
include_grant_scopes: NotRequired[bool]
state: NotRequired[str]
login_hint: NotRequired[str]
credential_id: NotRequired[str]


class URLForAdminConsentConfig(URLForAuthenticationConfig):
Expand Down
2 changes: 2 additions & 0 deletions nylas/models/connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class BaseCreateConnectorRequest(TypedDict):
"""

provider: Provider
active_credential_id: NotRequired[str]


class GoogleCreateConnectorSettings(TypedDict):
Expand Down Expand Up @@ -141,6 +142,7 @@ class UpdateConnectorRequest(TypedDict):
name: NotRequired[str]
settings: NotRequired[Dict[str, Any]]
scope: NotRequired[List[str]]
active_credential_id: NotRequired[str]


class ListConnectorQueryParams(ListQueryParams):
Expand Down
1 change: 1 addition & 0 deletions nylas/models/grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Grant:
updated_at: Optional[int] = None
provider_user_id: Optional[str] = None
settings: Optional[Dict[str, Any]] = None
credential_id: Optional[str] = None


class CreateGrantRequest(TypedDict):
Expand Down
19 changes: 19 additions & 0 deletions tests/resources/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ def test_url_for_oauth2(self, http_client):
== "https://test.nylas.com/v3/connect/auth?client_id=abc-123&redirect_uri=https%3A//example.com/oauth/callback&scope=email.read_only%20calendar%20contacts&login_hint=test%40gmail.com&provider=google&prompt=select_provider%2Cdetect&state=abc-123-state&response_type=code&access_type=online"
)

def test_url_for_oauth2_with_credential_id(self, http_client):
auth = Auth(http_client)
config = {
"client_id": "abc-123",
"redirect_uri": "https://example.com/oauth/callback",
"scope": ["Mail.Read", "User.Read"],
"login_hint": "[email protected]",
"provider": "microsoft",
"state": "abc-123-state",
"credential_id": "cred-abc-123",
}

url = auth.url_for_oauth2(config)

assert (
url
== "https://test.nylas.com/v3/connect/auth?client_id=abc-123&redirect_uri=https%3A//example.com/oauth/callback&scope=Mail.Read%20User.Read&login_hint=test%40outlook.com&provider=microsoft&state=abc-123-state&credential_id=cred-abc-123&response_type=code&access_type=online"
)

def test_exchange_code_for_token(self, http_client_token_exchange):
auth = Auth(http_client_token_exchange)
config = {
Expand Down
45 changes: 45 additions & 0 deletions tests/resources/test_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ def test_create_connector(self, http_client_response):
"POST", "/v3/connectors", None, None, request_body, overrides=None
)

def test_create_connector_with_active_credential_id(self, http_client_response):
connectors = Connectors(http_client_response)
request_body = {
"provider": "microsoft",
"settings": {
"client_id": "string",
"client_secret": "string",
"tenant": "common",
},
"scope": [
"Mail.Read",
"User.Read",
],
"active_credential_id": "cred-abc-123",
}

connectors.create(request_body=request_body)

http_client_response._execute.assert_called_once_with(
"POST", "/v3/connectors", None, None, request_body, overrides=None
)

def test_update_connector(self, http_client_response):
connectors = Connectors(http_client_response)
request_body = {
Expand All @@ -89,6 +111,29 @@ def test_update_connector(self, http_client_response):
"PATCH", "/v3/connectors/google", None, None, request_body, overrides=None
)

def test_update_connector_with_active_credential_id(self, http_client_response):
connectors = Connectors(http_client_response)
request_body = {
"settings": {
"client_id": "string",
"client_secret": "string",
},
"scope": [
"Mail.Read",
"User.Read",
],
"active_credential_id": "cred-xyz-789",
}

connectors.update(
provider="microsoft",
request_body=request_body,
)

http_client_response._execute.assert_called_once_with(
"PATCH", "/v3/connectors/microsoft", None, None, request_body, overrides=None
)

def test_destroy_connector(self, http_client_delete_response):
connectors = Connectors(http_client_delete_response)

Expand Down
29 changes: 29 additions & 0 deletions tests/resources/test_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,35 @@ def test_grant_deserialization(self, http_client):
assert grant.created_at == 1617817109
assert grant.updated_at == 1617817109

def test_grant_deserialization_with_credential_id(self, http_client):
grant_json = {
"id": "e19f8e1a-eb1c-41c0-b6a6-d2e59daf7f47",
"provider": "microsoft",
"grant_status": "valid",
"email": "[email protected]",
"scope": ["Mail.Read", "User.Read", "offline_access"],
"user_agent": "string",
"ip": "string",
"state": "my-state",
"created_at": 1617817109,
"updated_at": 1617817109,
"credential_id": "cred-abc-123",
}

grant = Grant.from_dict(grant_json)

assert grant.id == "e19f8e1a-eb1c-41c0-b6a6-d2e59daf7f47"
assert grant.provider == "microsoft"
assert grant.grant_status == "valid"
assert grant.email == "[email protected]"
assert grant.scope == ["Mail.Read", "User.Read", "offline_access"]
assert grant.user_agent == "string"
assert grant.ip == "string"
assert grant.state == "my-state"
assert grant.created_at == 1617817109
assert grant.updated_at == 1617817109
assert grant.credential_id == "cred-abc-123"

def test_list_grants(self, http_client_list_response):
grants = Grants(http_client_list_response)

Expand Down