Skip to content

Commit fa9edf6

Browse files
committed
Add 'smtp_required' option to Python SDK hosted auth
1 parent 8eda37c commit fa9edf6

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Unreleased
44
----------
55
* UAS multi-credential update
66
* Added `specific_time_availability` field to `AvailabilityParticipant` for overriding open hours on specific dates
7+
* Added `smtp_required` option to hosted authentication config to require users to enter SMTP settings during IMAP authentication
78

89
v6.14.2
910
----------

nylas/models/auth.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class URLForAuthenticationConfig(TypedDict):
3636
state: Optional state to be returned after authentication
3737
login_hint: Prefill the login name (usually email) during authorization flow.
3838
If a Grant for the provided email already exists, a Grant's re-auth will automatically be initiated.
39+
smtp_required: If True, adds options=smtp_required so users must enter SMTP settings during
40+
authentication. Relevant for IMAP; avoids grant errors when sending email later.
3941
"""
4042

4143
client_id: str
@@ -48,6 +50,7 @@ class URLForAuthenticationConfig(TypedDict):
4850
state: NotRequired[str]
4951
login_hint: NotRequired[str]
5052
credential_id: NotRequired[str]
53+
smtp_required: NotRequired[bool]
5154

5255

5356
class URLForAdminConsentConfig(URLForAuthenticationConfig):

nylas/resources/auth.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def _build_query(config: dict) -> dict:
3535
if "scope" in config:
3636
config["scope"] = " ".join(config["scope"])
3737

38+
if config.get("smtp_required"):
39+
config["options"] = "smtp_required"
40+
3841
return config
3942

4043

tests/resources/test_auth.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ def test_build_query(self):
3737
"scope": "email calendar",
3838
}
3939

40+
def test_build_query_with_smtp_required_true(self):
41+
config = {
42+
"foo": "bar",
43+
"scope": ["email"],
44+
"smtp_required": True,
45+
}
46+
result = _build_query(config)
47+
assert result["options"] == "smtp_required"
48+
49+
def test_build_query_smtp_required_false_omits_options(self):
50+
config = {
51+
"foo": "bar",
52+
"scope": ["email"],
53+
"smtp_required": False,
54+
}
55+
result = _build_query(config)
56+
assert "options" not in result
57+
58+
def test_build_query_smtp_required_omitted_omits_options(self):
59+
config = {"foo": "bar", "scope": ["email"]}
60+
result = _build_query(config)
61+
assert "options" not in result
62+
4063
def test_build_query_with_pkce(self):
4164
config = {
4265
"foo": "bar",
@@ -52,6 +75,17 @@ def test_build_query_with_pkce(self):
5275
"code_challenge_method": "s256",
5376
}
5477

78+
def test_build_query_with_pkce_and_smtp_required(self):
79+
config = {
80+
"foo": "bar",
81+
"scope": ["email"],
82+
"smtp_required": True,
83+
}
84+
result = _build_query_with_pkce(config, "secret-hash-123")
85+
assert result["options"] == "smtp_required"
86+
assert result["code_challenge"] == "secret-hash-123"
87+
assert result["code_challenge_method"] == "s256"
88+
5589
def test_build_query_with_admin_consent(self):
5690
config = {
5791
"foo": "bar",

0 commit comments

Comments
 (0)