Skip to content

Commit c04c3d8

Browse files
authored
Add 'smtp_required' option to Python SDK hosted auth (#458)
1 parent 8eda37c commit c04c3d8

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

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.pop("smtp_required", None):
39+
config["options"] = "smtp_required"
40+
3841
return config
3942

4043

tests/resources/test_auth.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,30 @@ 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+
assert "smtp_required" not in result # must not leak into URL params
49+
50+
def test_build_query_smtp_required_false_omits_options(self):
51+
config = {
52+
"foo": "bar",
53+
"scope": ["email"],
54+
"smtp_required": False,
55+
}
56+
result = _build_query(config)
57+
assert "options" not in result
58+
59+
def test_build_query_smtp_required_omitted_omits_options(self):
60+
config = {"foo": "bar", "scope": ["email"]}
61+
result = _build_query(config)
62+
assert "options" not in result
63+
4064
def test_build_query_with_pkce(self):
4165
config = {
4266
"foo": "bar",
@@ -52,6 +76,18 @@ def test_build_query_with_pkce(self):
5276
"code_challenge_method": "s256",
5377
}
5478

79+
def test_build_query_with_pkce_and_smtp_required(self):
80+
config = {
81+
"foo": "bar",
82+
"scope": ["email"],
83+
"smtp_required": True,
84+
}
85+
result = _build_query_with_pkce(config, "secret-hash-123")
86+
assert result["options"] == "smtp_required"
87+
assert "smtp_required" not in result # must not leak into URL params
88+
assert result["code_challenge"] == "secret-hash-123"
89+
assert result["code_challenge_method"] == "s256"
90+
5591
def test_build_query_with_admin_consent(self):
5692
config = {
5793
"foo": "bar",

0 commit comments

Comments
 (0)