@supa-media/convex 1.7.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/auth/twilioVerify.ts +15 -5
package/package.json
CHANGED
package/src/auth/twilioVerify.ts
CHANGED
|
@@ -8,14 +8,20 @@
|
|
|
8
8
|
* the code, so the app stores no secret and only records the result.
|
|
9
9
|
*
|
|
10
10
|
* The keys are the provider's: `TWILIO_ACCOUNT_SID`, `TWILIO_AUTH_TOKEN`,
|
|
11
|
-
* `TWILIO_VERIFY_SERVICE_SID`.
|
|
12
|
-
* `
|
|
11
|
+
* `TWILIO_VERIFY_SERVICE_SID`. An API key works in place of the auth token:
|
|
12
|
+
* `TWILIO_API_KEY_SID` with `TWILIO_API_KEY_SECRET`, which Twilio recommends
|
|
13
|
+
* because it can be revoked on its own. With no usable pair, `twilioVerifyKeys`
|
|
14
|
+
* answers `null`, and the app decides what that means. It should never mean
|
|
15
|
+
* "verified".
|
|
13
16
|
*/
|
|
14
17
|
|
|
15
18
|
export interface TwilioVerifyKeys {
|
|
16
19
|
accountSid: string;
|
|
20
|
+
/** The account's auth token, or the API key's secret when `apiKeySid` is set. */
|
|
17
21
|
authToken: string;
|
|
18
22
|
serviceSid: string;
|
|
23
|
+
/** Set when signing requests with an API key rather than the auth token. */
|
|
24
|
+
apiKeySid?: string;
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
export type TwilioSendResult =
|
|
@@ -34,15 +40,19 @@ export function twilioVerifyKeys(
|
|
|
34
40
|
const accountSid = env.TWILIO_ACCOUNT_SID?.trim();
|
|
35
41
|
const authToken = env.TWILIO_AUTH_TOKEN?.trim();
|
|
36
42
|
const serviceSid = env.TWILIO_VERIFY_SERVICE_SID?.trim();
|
|
37
|
-
if (!accountSid || !
|
|
38
|
-
return { accountSid, authToken, serviceSid };
|
|
43
|
+
if (!accountSid || !serviceSid) return null;
|
|
44
|
+
if (authToken) return { accountSid, authToken, serviceSid };
|
|
45
|
+
const apiKeySid = env.TWILIO_API_KEY_SID?.trim();
|
|
46
|
+
const apiKeySecret = env.TWILIO_API_KEY_SECRET?.trim();
|
|
47
|
+
if (!apiKeySid || !apiKeySecret) return null;
|
|
48
|
+
return { accountSid, authToken: apiKeySecret, serviceSid, apiKeySid };
|
|
39
49
|
}
|
|
40
50
|
|
|
41
51
|
function request(keys: TwilioVerifyKeys, path: string, body: Record<string, string>, fetchImpl: Fetch) {
|
|
42
52
|
return fetchImpl(`https://verify.twilio.com/v2/Services/${keys.serviceSid}/${path}`, {
|
|
43
53
|
method: "POST",
|
|
44
54
|
headers: {
|
|
45
|
-
Authorization: `Basic ${btoa(`${keys.accountSid}:${keys.authToken}`)}`,
|
|
55
|
+
Authorization: `Basic ${btoa(`${keys.apiKeySid ?? keys.accountSid}:${keys.authToken}`)}`,
|
|
46
56
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
47
57
|
},
|
|
48
58
|
body: new URLSearchParams(body),
|