Skip to content

Commit 4880691

Browse files
authored
Remove TOTP seed of a user (#440)
+ tests related to descope/etc#9344
1 parent a8f00a8 commit 4880691

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

lib/management/paths.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export default {
3333
setActivePassword: '/v1/mgmt/user/password/set/active',
3434
expirePassword: '/v1/mgmt/user/password/expire',
3535
removeAllPasskeys: '/v1/mgmt/user/passkeys/delete',
36+
removeTOTPSeed: '/v1/mgmt/user/totp/delete',
3637
generateOTPForTest: '/v1/mgmt/tests/generate/otp',
3738
generateMagicLinkForTest: '/v1/mgmt/tests/generate/magiclink',
3839
generateEnchantedLinkForTest: '/v1/mgmt/tests/generate/enchantedlink',

lib/management/user.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,36 @@ describe('Management User', () => {
18721872
});
18731873
});
18741874

1875+
describe('removeTOTPSeed', () => {
1876+
it('should send the correct request and receive correct response', async () => {
1877+
const httpResponse = {
1878+
ok: true,
1879+
json: () => {},
1880+
clone: () => ({
1881+
json: () => Promise.resolve({}),
1882+
}),
1883+
status: 200,
1884+
};
1885+
mockHttpClient.post.mockResolvedValue(httpResponse);
1886+
1887+
const loginId = 'some-id';
1888+
const resp = await management.user.removeTOTPSeed(loginId);
1889+
1890+
expect(mockHttpClient.post).toHaveBeenCalledWith(
1891+
apiPaths.user.removeTOTPSeed,
1892+
{ loginId },
1893+
{ token: 'key' },
1894+
);
1895+
1896+
expect(resp).toEqual({
1897+
code: 200,
1898+
data: {},
1899+
ok: true,
1900+
response: httpResponse,
1901+
});
1902+
});
1903+
});
1904+
18751905
describe('history', () => {
18761906
it('should send the correct request and receive correct response', async () => {
18771907
const usersHistoryRes = [

lib/management/user.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,18 @@ const withUser = (sdk: CoreSdk, managementKey?: string) => {
992992
(data) => data,
993993
),
994994

995+
/**
996+
* Removes TOTP seed for the user with the given login ID.
997+
* Note: The user might not be able to login anymore if they have no other authentication
998+
* methods or a verified email/phone.
999+
* @param loginId The login ID of the user
1000+
*/
1001+
removeTOTPSeed: (loginId: string): Promise<SdkResponse<never>> =>
1002+
transformResponse<never>(
1003+
sdk.httpClient.post(apiPaths.user.removeTOTPSeed, { loginId }, { token: managementKey }),
1004+
(data) => data,
1005+
),
1006+
9951007
/**
9961008
* Retrieve users' authentication history, by the given user's ids.
9971009
* @param userIds The user IDs

0 commit comments

Comments
 (0)