@@ -12,22 +12,27 @@ import type { OAuthConfig } from '#auth-utils'
1212 */
1313export interface OAuthWorkOSConfig {
1414 /**
15- * WorkOS OAuth Client ID
15+ * WorkOS OAuth Client ID *required
1616 * @default process.env.NUXT_OAUTH_WORKOS_CLIENT_ID
1717 */
1818 clientId ?: string
1919 /**
20- * WorkOS OAuth Client Secret (API Key)
20+ * WorkOS OAuth Client Secret (API Key) *required
2121 * @default process.env.NUXT_OAUTH_WORKOS_CLIENT_SECRET
2222 */
2323 clientSecret ?: string
2424 /**
25- * WorkOS OAuth Connection ID (Not required for WorkOS)
25+ * WorkOS OAuth Organization ID *not required
26+ * @default process.env.NUXT_OAUTH_WORKOS_ORGANIZATION_ID
27+ */
28+ organizationId ?: string
29+ /**
30+ * WorkOS OAuth Connection ID *not required
2631 * @default process.env.NUXT_OAUTH_WORKOS_CONNECTION_ID
2732 */
2833 connectionId ?: string
2934 /**
30- * WorkOS OAuth screen hint
35+ * WorkOS OAuth screen hint *not required
3136 * @default 'sign-in'
3237 */
3338 screenHint ?: 'sign-in' | 'sign-up'
@@ -37,6 +42,7 @@ export interface OAuthWorkOSConfig {
3742 */
3843 redirectURL ?: string
3944}
45+
4046export interface OAuthWorkOSUser {
4147 object : 'user'
4248 id : string
@@ -74,7 +80,7 @@ export function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }: OA
7480 return handleMissingConfiguration ( event , 'workos' , [ 'clientId' , 'clientSecret' ] , onError )
7581 }
7682
77- const query = getQuery < { code ?: string , state ?: string , error ?: string , error_description ?: string , returnURL ?: string } > ( event )
83+ const query = getQuery < { code ?: string , state ?: string , error ?: string , error_description ?: string } > ( event )
7884 const redirectURL = config . redirectURL || getOAuthRedirectURL ( event )
7985
8086 if ( query . error ) {
@@ -89,16 +95,14 @@ export function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }: OA
8995 response_type : 'code' ,
9096 provider : 'authkit' ,
9197 client_id : config . clientId ,
92- redirect_uri : redirectURL ,
93- connection_id : config . connectionId ,
94- screen_hint : config . screenHint ,
98+ redirect_uri : redirectURL || undefined ,
99+ connection_id : config . connectionId || undefined ,
100+ screen_hint : config . screenHint || 'sign-in' ,
101+ organization_id : config . organizationId || undefined ,
95102 } ) ,
96103 )
97104 }
98105
99- const ip_address = getRequestIP ( event )
100- const user_agent = getRequestHeader ( event , 'user-agent' )
101-
102106 const authenticateResponse : OAuthWorkOSAuthenticateResponse = await requestAccessToken ( 'https://api.workos.com/user_management/authenticate' , {
103107 headers : {
104108 'Content-Type' : 'application/json' ,
@@ -108,8 +112,8 @@ export function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }: OA
108112 client_id : config . clientId ,
109113 client_secret : config . clientSecret ,
110114 redirect_uri : redirectURL ,
111- ip_address,
112- user_agent,
115+ ip_address : getRequestIP ( event ) ,
116+ user_agent : getRequestHeader ( event , 'user-agent' ) ,
113117 code : query . code ,
114118 } ,
115119 } )
0 commit comments