Skip to content

Commit 9bc5ade

Browse files
committed
bug(auth): Allow startup even if twilio is not configured.
1 parent 7200af6 commit 9bc5ade

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

libs/accounts/recovery-phone/src/lib/twilio.config.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import { IsBoolean, IsString } from 'class-validator';
1010
export class TwilioConfig {
1111
/**
1212
* Determines which credential set to use. Options are
13-
* - test - uses the testing account sid and testing auth token
14-
* - default - uses the account sid and auth token
15-
* - apiKeys - ues the account sid, apiKey and apiSecret
13+
* - '' - An unauthenticated twilio client will be created. All calls to twilio will fail.
14+
* - 'test' - uses the testing account sid and testing auth token
15+
* - 'default' - uses the account sid and auth token
16+
* - 'apiKeys' - ues the account sid, apiKey and apiSecret
1617
*/
1718
@IsString()
18-
credentialMode!: 'test' | 'default' | 'apiKeys';
19+
credentialMode!: 'test' | 'default' | 'apiKeys' | '';
1920

2021
@IsString()
2122
testAuthToken?: string;

libs/accounts/recovery-phone/src/lib/twilio.provider.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ConfigService } from '@nestjs/config';
66
import { Provider } from '@nestjs/common';
77
import { Twilio } from 'twilio';
88
import { TwilioConfig } from './twilio.config';
9+
import { MozLoggerService } from '@fxa/shared/mozlog';
910

1011
export const TwilioConfigProvider = {
1112
provide: TwilioConfig,
@@ -21,7 +22,7 @@ export const TwilioProvider = Symbol('TwilioProvider');
2122
// Should this be moved to shared?
2223
export const TwilioFactory: Provider<Twilio> = {
2324
provide: TwilioProvider,
24-
useFactory: (config: TwilioConfig) => {
25+
useFactory: (config: TwilioConfig, log?: MozLoggerService) => {
2526
const {
2627
credentialMode,
2728
testAccountSid,
@@ -32,6 +33,13 @@ export const TwilioFactory: Provider<Twilio> = {
3233
apiSecret,
3334
} = config;
3435

36+
if (credentialMode === '') {
37+
log?.debug(
38+
'Twilio will not be available. Check readme for info about configuring Twilio.'
39+
);
40+
return new Twilio('AC123', '');
41+
}
42+
3543
// Okay for test, dev, and CI when using real phone numbers
3644
if (credentialMode === 'default' && accountSid && authToken) {
3745
return new Twilio(accountSid, authToken);

packages/fxa-auth-server/config/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -2240,42 +2240,42 @@ const convictConf = convict({
22402240
},
22412241
twilio: {
22422242
credentialMode: {
2243-
default: 'default',
2244-
doc: 'Which credential set to use. Options are test, default, or apiKeys.',
2243+
default: '',
2244+
doc: 'Which credential set to use. To enable twilio, options are "", "test", "default", or "apiKeys".',
22452245
env: 'RECOVERY_PHONE__TWILIO__CREDENTIAL_MODE',
22462246
format: String,
22472247
},
22482248
testAccountSid: {
22492249
default: 'AC_REPLACEMEWITHKEY',
2250-
doc: 'Twilio Testing Account ID. Note must be used for tests leveraging Twilio magic phone numbers.',
2250+
doc: 'Twilio Testing Account ID. Note must be used for tests leveraging Twilio magic phone numbers. Required when credentialMode is test.',
22512251
env: 'RECOVERY_PHONE__TWILIO__TEST_ACCOUNT_SID',
22522252
format: String,
22532253
},
22542254
testAuthToken: {
22552255
default: '',
2256-
doc: 'Twilio Testing Account Auth Token. Note must be used for tests leverage Twilio magic phone numbers.',
2256+
doc: 'Twilio Testing Account Auth Token. Note must be used for tests leverage Twilio magic phone numbers. Required when credentialMode is test.',
22572257
env: 'RECOVERY_PHONE__TWILIO__TEST_AUTH_TOKEN',
22582258
format: String,
22592259
},
22602260
accountSid: {
22612261
default: 'AC_REPLACEMEWITHKEY',
2262-
doc: 'Twilio Account ID',
2262+
doc: 'Twilio Account ID. Required when credentialMode is default or apiKeys.',
22632263
env: 'RECOVERY_PHONE__TWILIO__ACCOUNT_SID',
22642264
format: String,
22652265
},
22662266
authToken: {
22672267
default: '',
2268-
doc: 'Twilio Auth Token to access api. Note, using apiKey/apiSecret is preferred.',
2268+
doc: 'Twilio Auth Token to access api. Note, using apiKey/apiSecret is preferred. Required when credentialMode is default.',
22692269
env: 'RECOVERY_PHONE__TWILIO__AUTH_TOKEN',
22702270
},
22712271
apiKey: {
22722272
default: '',
2273-
doc: 'An api key used to access the twilio rest api. Note, when provided the authToken is no longer needed.',
2273+
doc: 'An api key used to access the twilio rest api. Required when credentialMode is apiKeys.',
22742274
env: 'RECOVERY_PHONE__TWILIO__API_KEY',
22752275
},
22762276
apiSecret: {
22772277
default: '',
2278-
doc: 'A secret used in conjunction with the apiKey to access the twilio rest api.',
2278+
doc: 'A secret used in conjunction with the apiKey to access the twilio rest api. Required when credentialMode is apiKeys.',
22792279
env: 'RECOVERY_PHONE__TWILIO__API_SECRET',
22802280
},
22812281
webhookUrl: {

0 commit comments

Comments
 (0)