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
6 changes: 6 additions & 0 deletions src/models/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/resources/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
23 changes: 23 additions & 0 deletions tests/resources/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down