Skip to content

Commit be81ef4

Browse files
authored
Add authenticationMethod to the authentication response serializer (#1031)
## 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 6a1f25e commit be81ef4

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/user-management/interfaces/authentication-response.interface.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { Impersonator, ImpersonatorResponse } from './impersonator.interface';
22
import { User, UserResponse } from './user.interface';
33

4+
type AuthenticationMethod =
5+
| 'SSO'
6+
| 'Password'
7+
| 'GitHubOAuth'
8+
| 'GoogleOAuth'
9+
| 'MicrosoftOAuth'
10+
| 'MagicAuth'
11+
| 'Impersonation';
412
export interface AuthenticationResponse {
513
user: User;
614
organizationId?: string;
715
accessToken: string;
816
refreshToken: string;
917
impersonator?: Impersonator;
18+
authenticationMethod?: AuthenticationMethod;
1019
}
1120

1221
export interface AuthenticationResponseResponse {
@@ -15,6 +24,7 @@ export interface AuthenticationResponseResponse {
1524
access_token: string;
1625
refresh_token: string;
1726
impersonator?: ImpersonatorResponse;
27+
authentication_method?: AuthenticationMethod;
1828
}
1929

2030
export interface RefreshAuthenticationResponse {

src/user-management/serializers/authentication-response.serializer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const deserializeAuthenticationResponse = (
1414
organization_id,
1515
access_token,
1616
refresh_token,
17+
authentication_method,
1718
impersonator,
1819
...rest
1920
} = authenticationResponse;
@@ -24,6 +25,7 @@ export const deserializeAuthenticationResponse = (
2425
accessToken: access_token,
2526
refreshToken: refresh_token,
2627
impersonator,
28+
authenticationMethod: authentication_method,
2729
...rest,
2830
};
2931
};

src/user-management/user-management.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ describe('UserManagement', () => {
163163
});
164164
});
165165

166+
it('deserializes authentication_method', async () => {
167+
fetchOnce({
168+
user: userFixture,
169+
authentication_method: 'Password',
170+
});
171+
172+
const resp = await workos.userManagement.authenticateWithCode({
173+
clientId: 'proj_whatever',
174+
code: 'or this',
175+
});
176+
177+
expect(resp).toMatchObject({
178+
user: {
179+
180+
},
181+
authenticationMethod: 'Password',
182+
});
183+
});
184+
166185
describe('when the code is for an impersonator', () => {
167186
it('deserializes the impersonator metadata', async () => {
168187
fetchOnce({

0 commit comments

Comments
 (0)