Skip to content

Commit 98a34ca

Browse files
authored
Add authentication method to response interfaces and serializer (#99)
* Add authentication method to response interfaces and serializer - Introduced `AuthenticationMethod` type to define various authentication methods. - Updated `AuthenticationResponse` and `AuthenticationResponseRaw` interfaces to include `authenticationMethod`. - Modified the `deserializeAuthenticationResponse` function to handle the new `authentication_method` field. - Updated tests to include `authenticationMethod` in session data setup. * adds auth method types and adds to storage and session * adds auth method as export type
1 parent 892e966 commit 98a34ca

File tree

7 files changed

+34
-1
lines changed

7 files changed

+34
-1
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export { createClient } from "./create-client";
22
export { getClaims } from "./utils/session-data";
33
export {
44
User,
5+
AuthenticationMethod,
56
AuthenticationResponse,
67
OnRefreshResponse,
78
JWTPayload,

src/interfaces/authentication-response.interface.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
import { User, UserRaw } from "./user.interface";
22
import { Impersonator, ImpersonatorRaw } from "./impersonator.interface";
33

4+
export type AuthenticationMethod =
5+
| "SSO"
6+
| "Password"
7+
| "Passkey"
8+
| "AppleOAuth"
9+
| "BitbucketOAuth"
10+
| "CrossAppAuth"
11+
| "DiscordOAuth"
12+
| "ExternalAuth"
13+
| "GitHubOAuth"
14+
| "GitLabOAuth"
15+
| "GoogleOAuth"
16+
| "LinkedInOAuth"
17+
| "MicrosoftOAuth"
18+
| "SalesforceOAuth"
19+
| "SlackOAuth"
20+
| "VercelMarketplaceOAuth"
21+
| "VercelOAuth"
22+
| "XeroOAuth"
23+
| "MagicAuth"
24+
| "Impersonation"
25+
| "MigratedSession";
26+
427
export interface AuthenticationResponse {
528
user: User;
629
accessToken: string;
730
refreshToken: string;
31+
authenticationMethod: AuthenticationMethod;
832
organizationId?: string;
933
impersonator?: Impersonator;
1034
}
@@ -15,6 +39,7 @@ export interface AuthenticationResponseRaw {
1539
user: UserRaw;
1640
access_token: string;
1741
refresh_token: string;
42+
authentication_method: AuthenticationMethod;
1843
organization_id?: string;
1944
impersonator?: ImpersonatorRaw;
2045
}

src/interfaces/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type {
2+
AuthenticationMethod,
23
AuthenticationResponse,
34
AuthenticationResponseRaw,
45
OnRefreshResponse,

src/serializers/authentication-response.serializer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const deserializeAuthenticationResponse = (
1212
organization_id,
1313
access_token,
1414
refresh_token,
15+
authentication_method,
1516
impersonator,
1617
...rest
1718
} = authenticationResponse;
@@ -21,6 +22,7 @@ export const deserializeAuthenticationResponse = (
2122
organizationId: organization_id,
2223
accessToken: access_token,
2324
refreshToken: refresh_token,
25+
authenticationMethod: authentication_method,
2426
impersonator,
2527
...rest,
2628
};

src/utils/session-data.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe("setSessionData", () => {
2727
setSessionData({
2828
accessToken: validToken,
2929
refreshToken: "refresh_token",
30+
authenticationMethod: "Password",
3031
user: mockUser,
3132
});
3233
expect(memoryStorage.getItem(storageKeys.accessToken)).toBe(validToken);

src/utils/session-data.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ export function setSessionData(
1616
data: AuthenticationResponse,
1717
{ devMode = false } = {},
1818
) {
19-
const { user, accessToken, refreshToken } = data;
19+
const { user, accessToken, refreshToken, authenticationMethod } = data;
2020
memoryStorage.setItem(storageKeys.user, user);
2121
memoryStorage.setItem(storageKeys.accessToken, accessToken);
22+
memoryStorage.setItem(storageKeys.authenticationMethod, authenticationMethod);
2223
(devMode ? window.localStorage : memoryStorage).setItem(
2324
storageKeys.refreshToken,
2425
refreshToken,
@@ -34,6 +35,7 @@ export function setSessionData(
3435
export function removeSessionData({ devMode = false } = {}) {
3536
memoryStorage.removeItem(storageKeys.user);
3637
memoryStorage.removeItem(storageKeys.accessToken);
38+
memoryStorage.removeItem(storageKeys.authenticationMethod);
3739
(devMode ? window.localStorage : memoryStorage).removeItem(
3840
storageKeys.refreshToken,
3941
);

src/utils/storage-keys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export const storageKeys = {
44
accessToken: "workos:access-token",
55
refreshToken: "workos:refresh-token",
66
expiresAt: "workos:expires-at",
7+
authenticationMethod: "workos:authentication-method",
78
} as const;

0 commit comments

Comments
 (0)