Skip to content

remove accessToken from being sent to client components#206

Merged
nicknisi merged 4 commits intomainfrom
nicknisi/remove-client-access-token
Feb 21, 2025
Merged

remove accessToken from being sent to client components#206
nicknisi merged 4 commits intomainfrom
nicknisi/remove-client-access-token

Conversation

@nicknisi
Copy link
Member

@nicknisi nicknisi commented Feb 21, 2025

Breaking change

This removes accessToken from being accessible in client components. The following is no longer allowed.

const { accessToken } = useAuth(); // no longer accessible

This pull request focuses on removing the accessToken from the client-side code to enhance security and simplify the auth object. The most important changes include sanitizing the auth object, updating actions to use the sanitized auth object, and modifying components to remove references to accessToken.

Security Improvements:

  • Added a sanitize function to remove the accessToken from the auth object before it is used on the client side. (src/actions.ts)
  • Updated getAuthAction and refreshAuthAction to use the sanitize function. (src/actions.ts) [1] [2]

Component Updates:

  • Removed accessToken from the AuthContextType type definition. (src/components/authkit-provider.tsx)
  • Removed accessToken state and related code from the AuthKitProvider component. (src/components/authkit-provider.tsx) [1] [2] [3] [4] [5]

Test Adjustments:

  • Removed accessToken from test mock data in useAuth test suite. (__tests__/authkit-provider.spec.tsx)

@nicknisi nicknisi requested a review from cmatheson February 21, 2025 20:39
@@ -220,7 +220,6 @@ describe('useAuth', () => {
entitlements: ['feature1'],
impersonator: { email: 'admin@example.com' },
oauthTokens: { access_token: 'token123' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably remove these oauthTokens too for good measure (maybe someone else on the team thinks differently?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like that's only referenced in that test and isn't actually passed to the client. We're only sending UserInfo | NoUserInfo from these actions

export interface UserInfo {
user: User;
sessionId: string;
organizationId?: string;
role?: string;
permissions?: string[];
entitlements?: string[];
impersonator?: Impersonator;
accessToken: string;
}
export interface NoUserInfo {
user: null;
sessionId?: undefined;
organizationId?: undefined;
role?: undefined;
permissions?: undefined;
entitlements?: undefined;
impersonator?: undefined;
accessToken?: undefined;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and removed oauthTokens here from the mock return.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i see, we pass the oauthTokens to an onSuccess callback but otherwise don't store them at all 👍

@nicknisi nicknisi merged commit ceb83a3 into main Feb 21, 2025
4 checks passed
@nicknisi nicknisi deleted the nicknisi/remove-client-access-token branch February 21, 2025 21:30
@nicknisi nicknisi mentioned this pull request Feb 21, 2025
@statico
Copy link

statico commented Mar 13, 2025

Hi there! How does this affect the <UsersManagement /> widget as described in the WorkOS Widgets docs? Those docs say to use getAccessToken from useAuth(). (cc @tburgin)

@cmatheson
Copy link
Contributor

@statico getAccessToken() is for authkit-react. Nextjs falls into the backend integrations bucket (token docs)

CleanShot 2025-03-13 at 14 50 36@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants