You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: libs/accounts/recovery-phone/README.md
+15
Original file line number
Diff line number
Diff line change
@@ -33,3 +33,18 @@ Also it's good to note that there are some caveats about configuration for webho
33
33
the `X-Twilio-Signature` header. If you are using twilio API keys, then we need the fxaPublicKey/fxaPrivateKey pair set in the config. Reach
34
34
out to a teammate for this value, or generate one yourself. There's a method that will do this in the `util.ts`. And make sure this key pair
35
35
is in the config!
36
+
37
+
## Configuration & Twilio Client Modes
38
+
39
+
In order to use this library, we must configure Twilio. Twilio is unique in that the client can essentially operate in two different modes and these
40
+
modes are dictated by the credentials passed to the client.
41
+
42
+
There is a 'testing' mode and a 'default' mode. The testing mode cannot send messages to real phone numbers, but it can send messages to 'magic' testing
43
+
numbers that are reserved and maintained by Twilio for testing purposes and are free to send SMS to. The default mode can send out real text messages,
44
+
but cannot send messages to 'magic' testing numbers.
45
+
46
+
This design results in a scenario where we often have to switch between testing and default modes. In order to make this easy, we've added a 'credentialMode'
47
+
to signal which credentials set should be used.
48
+
49
+
The config class can be found in `src/lib/twilio-config.ts`. An example application of this config can be found in `packages/fxa-auth-server/config/index.ts`, and
50
+
auth-server's read me has some doc on how to configure its env for Twilio.
Copy file name to clipboardexpand all lines: packages/fxa-auth-server/README.md
+42
Original file line number
Diff line number
Diff line change
@@ -156,6 +156,48 @@ Rate-limiting and blocking is handled by fxa-customs-server. By default, these p
156
156
157
157
The customs-server can be enabled for local testing by changing the dev config to `"customsUrl":"http://localhost:7000"`.
158
158
159
+
### Recovery Phone Config
160
+
161
+
Recovery phone uses twilio to send SMS. Twilio has two different modes it can operate in based on the credentials provided.
162
+
163
+
There is a 'test' mode and a 'default' mode. The testing mode cannot send messages to real phone numbers, but it can send
164
+
messages to 'magic' testing numbers that are reserved and maintained by Twilio for testing purposes and are free to send SMS
165
+
to. The default mode can send out real messages, but cannot send messages to 'magic' testing numbers. These credentials can
166
+
be obtained by going to twilio.com logging into your account, and finding them in the testing console. If you are new to the
167
+
FxA team, contact a team member to get twilio access.
168
+
169
+
The 'test' mode can send SMS to magic test numbers at no cost. This is what we use for unit/integration testing.
170
+
171
+
The 'default' mode can send SMS to real numbers, but will incur const, and cannot send messages to magic test numbers. This
172
+
is what we use for manual testing.
173
+
174
+
To make switching between these modes easy, we've created the `twilio.credentialMode` configuration setting. Simply set the
175
+
apiKeys and testCredentials, then toggle `credentialMode` from test to apiKeys depending on how you are testing. Here's a
176
+
snippet from .env that shows an example of this.
177
+
178
+
```
179
+
RECOVERY_PHONE__ENABLED=true
180
+
RECOVERY_PHONE__TWILIO__ACCOUNT_SID=######
181
+
182
+
# Set apiKeys for manual testing
183
+
RECOVERY_PHONE__TWILIO__API_KEY=######
184
+
RECOVERY_PHONE__TWILIO__API_SECRET=######
185
+
186
+
# These are the specific Twilio test credentials that allow us to send out sms to
187
+
# magic numbers and incur no cost. Set these so we can run our automated tests.
188
+
RECOVERY_PHONE__TWILIO__TEST_ACCOUNT_SID=######
189
+
RECOVERY_PHONE__TWILIO__TEST_AUTH_TOKEN=######
190
+
191
+
# Important! Toggle this value between 'apiKeys' or 'test'. Depending on how
192
+
# you are testing.
193
+
RECOVERY_PHONE__TWILIO__CREDENTIAL_MODE=apiKeys
194
+
```
195
+
196
+
TIP:
197
+
198
+
- Applying .env file state is easy simply run `dotenv -- yarn start`.
199
+
- After toggling `RECOVERY_PHONE__TWILIO__CREDENTIAL_MODE` you can restart auth-server like this: `dotenv -- yarn pm2 restart auth --update-env`. This avoids having to stop and start the stack again.
200
+
159
201
### Token Pruning
160
202
161
203
We need to be able to periodically remove old tokens and codes. This can be accomplished via the token pruning script in the scripts directory.
0 commit comments