Skip to content

Commit

Permalink
OTP voice support RELEASE (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
dorsha authored Apr 3, 2024
1 parent f6a1995 commit 129c37f
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ try {

### OTP Authentication

Send a user a one-time password (OTP) using your preferred delivery method (_email / SMS_). An email address or phone number must be provided accordingly.
Send a user a one-time password (OTP) using your preferred delivery method (_Email / SMS / Voice call / WhatsApp_). An email address or phone number must be provided accordingly.

The user can either `sign up`, `sign in` or `sign up or in`

Expand Down Expand Up @@ -1253,7 +1253,7 @@ const q = await descopeClient.management.authz.hasRelations([
### Utils for your end to end (e2e) tests and integration tests

To ease your e2e tests, we exposed dedicated management methods,
that way, you don't need to use 3rd party messaging services in order to receive sign-in/up Emails or SMS, and avoid the need of parsing the code and token from them.
that way, you don't need to use 3rd party messaging services in order to receive sign-in/up Email, SMS, Voice call or WhatsApp, and avoid the need of parsing the code and token from them.

```typescript
// User for test can be created, this user will be able to generate code/link without
Expand All @@ -1274,7 +1274,7 @@ await descopeClient.management.user.deleteAllTestUsers();

// OTP code can be generated for test user, for example:
const { code } = await descopeClient.management.user.generateOTPForTestUser(
'sms',
'sms', // you can use also 'email', 'whatsapp', 'voice'
'[email protected]',
);
// Now you can verify the code is valid (using descopeClient.auth.*.verify for example)
Expand Down
3 changes: 3 additions & 0 deletions examples/commonjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ const getMethodAndLoginId = (req) => {
if (req.body.sms) {
return { loginId: req.body.sms, deliveryMethod: DescopeClient.DeliveryMethods.SMS };
}
if (req.body.voice) {
return { loginId: req.body.voice, deliveryMethod: DescopeClient.DeliveryMethods.voice };
}
if (req.body.whatsapp) {
return {
loginId: req.body.whatsapp,
Expand Down
10 changes: 5 additions & 5 deletions examples/commonjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions examples/es6/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/es6/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ const getMethodAndLoginId = (req: Request): { loginId: string; deliveryMethod: D
if (req.body.sms) {
return { loginId: req.body.sms as string, deliveryMethod: 'sms' };
}
if (req.body.voice) {
return { loginId: req.body.voice as string, deliveryMethod: 'voice' };
}
if (req.body.whatsapp) {
return { loginId: req.body.whatsapp as string, deliveryMethod: 'whatsapp' };
}
Expand Down
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ const nodeSdk = ({ managementKey, publicKey, ...config }: NodeSdkArgs) => {
[
'otp.verify.email',
'otp.verify.sms',
'otp.verify.voice',
'otp.verify.whatsapp',
'magicLink.verify',
'enchantedLink.signUp',
Expand Down
32 changes: 32 additions & 0 deletions lib/management/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,38 @@ describe('Management User', () => {
});
});

it('should send the correct request and receive correct response for voice', async () => {
const mockResponse = { loginId: 'some-id', code: '123456' };
const httpResponse = {
ok: true,
json: () => mockResponse,
clone: () => ({
json: () => Promise.resolve(mockResponse),
}),
status: 200,
};
mockHttpClient.post.mockResolvedValue(httpResponse);

const loginOptions: LoginOptions = {
stepup: true,
};
const resp: SdkResponse<GenerateOTPForTestResponse> =
await management.user.generateOTPForTestUser('voice', 'some-id', loginOptions);

expect(mockHttpClient.post).toHaveBeenCalledWith(
apiPaths.user.generateOTPForTest,
{ loginId: 'some-id', deliveryMethod: 'voice', loginOptions },
{ token: 'key' },
);

expect(resp).toEqual({
code: 200,
data: mockResponse,
ok: true,
response: httpResponse,
});
});

it('should send the correct request and receive correct response when passing embedded delivery method', async () => {
const mockResponse = { loginId: 'some-id', code: '123456' };
const httpResponse = {
Expand Down
2 changes: 1 addition & 1 deletion lib/management/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ const withUser = (sdk: CoreSdk, managementKey?: string) => {
/**
* Generate OTP for the given login ID of a test user.
* Choose the selected delivery method for verification.
* Returns the code for the login (exactly as it sent via Email or SMS)
* Returns the code for the login (exactly as it sent via Email, SMS, Voice call or WhatsApp)
* This is useful when running tests and don't want to use 3rd party messaging services
*
* @param deliveryMethod optional DeliveryMethod
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"typescript": "^4.6.4"
},
"dependencies": {
"@descope/core-js-sdk": "2.11.5",
"@descope/core-js-sdk": "2.12.0",
"cross-fetch": "^4.0.0",
"jose": "5.2.2",
"tslib": "^2.0.0"
Expand Down

0 comments on commit 129c37f

Please sign in to comment.