Skip to content

Commit 387d60b

Browse files
Add authenticateWithTotp method (#856)
## Description ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [ ] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.
1 parent dd6a623 commit 387d60b

13 files changed

+148
-61
lines changed

src/users/interfaces/authenticate-user-with-token-options.interface.ts renamed to src/users/interfaces/authenticate-with-code-options.interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface AuthenticateUserWithCodeOptions {
1+
export interface AuthenticateWithCodeOptions {
22
clientId: string;
33
code: string;
44
}
@@ -7,7 +7,7 @@ export interface AuthenticateUserWithCodeCredentials {
77
clientSecret: string | undefined;
88
}
99

10-
export interface SerializedAuthenticateUserWithCodeOptions {
10+
export interface SerializedAuthenticateWithCodeOptions {
1111
grant_type: 'authorization_code';
1212
client_id: string;
1313
client_secret: string | undefined;

src/users/interfaces/authenticate-user-with-magic-auth-options.interface.ts renamed to src/users/interfaces/authenticate-with-magic-auth-options.interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface AuthenticateUserWithMagicAuthOptions {
1+
export interface AuthenticateWithMagicAuthOptions {
22
clientId: string;
33
code: string;
44
userId: string;
@@ -10,7 +10,7 @@ export interface AuthenticateUserWithMagicAuthCredentials {
1010
clientSecret: string | undefined;
1111
}
1212

13-
export interface SerializedAuthenticateUserWithMagicAuthOptions {
13+
export interface SerializedAuthenticateWithMagicAuthOptions {
1414
grant_type: 'urn:workos:oauth:grant-type:magic-auth:code';
1515
client_id: string;
1616
client_secret: string | undefined;

src/users/interfaces/authenticate-user-with-password-options.interface.ts renamed to src/users/interfaces/authenticate-with-password-options.interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface AuthenticateUserWithPasswordOptions {
1+
export interface AuthenticateWithPasswordOptions {
22
clientId: string;
33
email: string;
44
password: string;
@@ -10,7 +10,7 @@ export interface AuthenticateUserWithPasswordCredentials {
1010
clientSecret: string | undefined;
1111
}
1212

13-
export interface SerializedAuthenticateUserWithPasswordOptions {
13+
export interface SerializedAuthenticateWithPasswordOptions {
1414
grant_type: 'password';
1515
client_id: string;
1616
client_secret: string | undefined;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export interface AuthenticateWithTotpOptions {
2+
clientId: string;
3+
code: string;
4+
pendingAuthenticationToken: string;
5+
authenticationChallengeId: string;
6+
}
7+
8+
export interface AuthenticateUserWithTotpCredentials {
9+
clientSecret: string | undefined;
10+
}
11+
12+
export interface SerializedAuthenticateWithTotpOptions {
13+
grant_type: 'urn:workos:oauth:grant-type:mfa-totp';
14+
client_id: string;
15+
client_secret: string | undefined;
16+
code: string;
17+
pending_authentication_token: string;
18+
authentication_challenge_id: string;
19+
}

src/users/interfaces/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export * from './add-user-to-organization-options.interface';
2-
export * from './authenticate-user-with-magic-auth-options.interface';
3-
export * from './authenticate-user-with-password-options.interface';
4-
export * from './authenticate-user-with-token-options.interface';
2+
export * from './authenticate-with-magic-auth-options.interface';
3+
export * from './authenticate-with-password-options.interface';
4+
export * from './authenticate-with-code-options.interface';
55
export * from './authentication-response.interface';
66
export * from './reset-password-options.interface';
77
export * from './send-password-reset-options.interface';

src/users/serializers/authenticate-user-with-code-options.serializer.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {
2+
AuthenticateUserWithCodeCredentials,
3+
AuthenticateWithCodeOptions,
4+
SerializedAuthenticateWithCodeOptions,
5+
} from '../interfaces';
6+
7+
export const serializeAuthenticateWithCodeOptions = (
8+
options: AuthenticateWithCodeOptions & AuthenticateUserWithCodeCredentials,
9+
): SerializedAuthenticateWithCodeOptions => ({
10+
grant_type: 'authorization_code',
11+
client_id: options.clientId,
12+
client_secret: options.clientSecret,
13+
code: options.code,
14+
});

src/users/serializers/authenticate-user-with-magic-auth-options.serializer.ts renamed to src/users/serializers/authenticate-with-magic-auth-options.serializer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {
22
AuthenticateUserWithMagicAuthCredentials,
3-
AuthenticateUserWithMagicAuthOptions,
4-
SerializedAuthenticateUserWithMagicAuthOptions,
3+
AuthenticateWithMagicAuthOptions,
4+
SerializedAuthenticateWithMagicAuthOptions,
55
} from '../interfaces';
66

7-
export const serializeAuthenticateUserWithMagicAuthOptions = (
8-
options: AuthenticateUserWithMagicAuthOptions &
7+
export const serializeAuthenticateWithMagicAuthOptions = (
8+
options: AuthenticateWithMagicAuthOptions &
99
AuthenticateUserWithMagicAuthCredentials,
10-
): SerializedAuthenticateUserWithMagicAuthOptions => ({
10+
): SerializedAuthenticateWithMagicAuthOptions => ({
1111
grant_type: 'urn:workos:oauth:grant-type:magic-auth:code',
1212
client_id: options.clientId,
1313
client_secret: options.clientSecret,

src/users/serializers/authenticate-user-with-password-options.serializer.ts renamed to src/users/serializers/authenticate-with-password-options.serializer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {
22
AuthenticateUserWithPasswordCredentials,
3-
AuthenticateUserWithPasswordOptions,
4-
SerializedAuthenticateUserWithPasswordOptions,
3+
AuthenticateWithPasswordOptions,
4+
SerializedAuthenticateWithPasswordOptions,
55
} from '../interfaces';
66

7-
export const serializeAuthenticateUserWithPasswordOptions = (
8-
options: AuthenticateUserWithPasswordOptions &
7+
export const serializeAuthenticateWithPasswordOptions = (
8+
options: AuthenticateWithPasswordOptions &
99
AuthenticateUserWithPasswordCredentials,
10-
): SerializedAuthenticateUserWithPasswordOptions => ({
10+
): SerializedAuthenticateWithPasswordOptions => ({
1111
grant_type: 'password',
1212
client_id: options.clientId,
1313
client_secret: options.clientSecret,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {} from '../interfaces';
2+
import {
3+
AuthenticateUserWithTotpCredentials,
4+
AuthenticateWithTotpOptions,
5+
SerializedAuthenticateWithTotpOptions,
6+
} from '../interfaces/authenticate-with-totp-options.interface';
7+
8+
export const serializeAuthenticateWithTotpOptions = (
9+
options: AuthenticateWithTotpOptions & AuthenticateUserWithTotpCredentials,
10+
): SerializedAuthenticateWithTotpOptions => ({
11+
grant_type: 'urn:workos:oauth:grant-type:mfa-totp',
12+
client_id: options.clientId,
13+
client_secret: options.clientSecret,
14+
code: options.code,
15+
authentication_challenge_id: options.authenticationChallengeId,
16+
pending_authentication_token: options.pendingAuthenticationToken,
17+
});

0 commit comments

Comments
 (0)