Skip to content

Commit cd09fc1

Browse files
authored
feat(auth): add smtpRequired option to enforce SMTP settings during I… (#702)
1 parent cd97b2c commit cd09fc1

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/models/auth.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ export interface URLForAuthenticationConfig {
5858
* If a Grant for the provided email already exists, a Grant's re-auth will automatically be initiated.
5959
*/
6060
loginHint?: string;
61+
/**
62+
* If set to true, the options=smtp_required parameter is added to the authentication URL.
63+
* This forces users to provide SMTP settings during IMAP authentication, preventing
64+
* send failures from missing SMTP configuration.
65+
*/
66+
smtpRequired?: boolean;
6167
}
6268

6369
/**

src/resources/auth.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ export class Auth extends Resource {
215215
if (config.state) {
216216
url.searchParams.set('state', config.state);
217217
}
218+
if (config.smtpRequired) {
219+
url.searchParams.set('options', 'smtp_required');
220+
}
218221

219222
return url;
220223
}

tests/resources/auth.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,29 @@ describe('Auth', () => {
219219
'https://test.api.nylas.com/v3/connect/auth?client_id=clientId&redirect_uri=https%3A%2F%2Fredirect.uri%2Fpath&access_type=online&response_type=code&provider=google&login_hint=loginHint&include_grant_scopes=true&scope=calendar&prompt=prompt&state=state'
220220
);
221221
});
222+
223+
it('should add options=smtp_required when smtpRequired is true', () => {
224+
const url = auth.urlForOAuth2({
225+
clientId: 'clientId',
226+
redirectUri: 'https://redirect.uri/path',
227+
provider: 'imap',
228+
smtpRequired: true,
229+
});
230+
231+
expect(url).toBe(
232+
'https://test.api.nylas.com/v3/connect/auth?client_id=clientId&redirect_uri=https%3A%2F%2Fredirect.uri%2Fpath&access_type=online&response_type=code&provider=imap&options=smtp_required'
233+
);
234+
});
235+
236+
it('should not add options parameter when smtpRequired is not set', () => {
237+
const url = auth.urlForOAuth2({
238+
clientId: 'clientId',
239+
redirectUri: 'https://redirect.uri/path',
240+
provider: 'imap',
241+
});
242+
243+
expect(url).not.toContain('options=');
244+
});
222245
});
223246

224247
describe('urlForAuthenticationPKCE', () => {

0 commit comments

Comments
 (0)