diff --git a/src/models/auth.ts b/src/models/auth.ts index 737dac10..ce4dcc0d 100644 --- a/src/models/auth.ts +++ b/src/models/auth.ts @@ -58,6 +58,12 @@ export interface URLForAuthenticationConfig { * If a Grant for the provided email already exists, a Grant's re-auth will automatically be initiated. */ loginHint?: string; + /** + * If set to true, the options=smtp_required parameter is added to the authentication URL. + * This forces users to provide SMTP settings during IMAP authentication, preventing + * send failures from missing SMTP configuration. + */ + smtpRequired?: boolean; } /** diff --git a/src/resources/auth.ts b/src/resources/auth.ts index d46f1a80..57e5acfc 100644 --- a/src/resources/auth.ts +++ b/src/resources/auth.ts @@ -215,6 +215,9 @@ export class Auth extends Resource { if (config.state) { url.searchParams.set('state', config.state); } + if (config.smtpRequired) { + url.searchParams.set('options', 'smtp_required'); + } return url; } diff --git a/tests/resources/auth.spec.ts b/tests/resources/auth.spec.ts index c106d77d..f2110ed3 100644 --- a/tests/resources/auth.spec.ts +++ b/tests/resources/auth.spec.ts @@ -219,6 +219,29 @@ describe('Auth', () => { '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' ); }); + + it('should add options=smtp_required when smtpRequired is true', () => { + const url = auth.urlForOAuth2({ + clientId: 'clientId', + redirectUri: 'https://redirect.uri/path', + provider: 'imap', + smtpRequired: true, + }); + + expect(url).toBe( + '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' + ); + }); + + it('should not add options parameter when smtpRequired is not set', () => { + const url = auth.urlForOAuth2({ + clientId: 'clientId', + redirectUri: 'https://redirect.uri/path', + provider: 'imap', + }); + + expect(url).not.toContain('options='); + }); }); describe('urlForAuthenticationPKCE', () => {