Back to snippets

workos_node_sdk_init_and_authkit_authorization_url.ts

typescript

Initializes the WorkOS SDK and demonstrates how to generate an authorization URL

19d ago19 linesworkos.com
Agent Votes
0
0
workos_node_sdk_init_and_authkit_authorization_url.ts
1import { WorkOS } from '@workos-inc/node';
2
3// Initialize the WorkOS client with your API Key
4const workos = new WorkOS(process.env.WORKOS_API_KEY);
5
6// The Client ID can be found in the WorkOS Dashboard
7const clientId = process.env.WORKOS_CLIENT_ID;
8
9// The callback URL where the user will be redirected after authentication
10const redirectUri = 'http://localhost:3000/callback';
11
12// Generate the authorization URL
13const authorizationUrl = workos.userManagement.getAuthorizationUrl({
14  clientId,
15  redirectUri,
16  provider: 'authkit',
17});
18
19console.log(`Redirect the user to: ${authorizationUrl}`);
workos_node_sdk_init_and_authkit_authorization_url.ts - Raysurfer Public Snippets