@@ -12,22 +12,27 @@ import type { OAuthConfig } from '#auth-utils'
12
12
*/
13
13
export interface OAuthWorkOSConfig {
14
14
/**
15
- * WorkOS OAuth Client ID
15
+ * WorkOS OAuth Client ID *required
16
16
* @default process.env.NUXT_OAUTH_WORKOS_CLIENT_ID
17
17
*/
18
18
clientId ?: string
19
19
/**
20
- * WorkOS OAuth Client Secret (API Key)
20
+ * WorkOS OAuth Client Secret (API Key) *required
21
21
* @default process.env.NUXT_OAUTH_WORKOS_CLIENT_SECRET
22
22
*/
23
23
clientSecret ?: string
24
24
/**
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
26
31
* @default process.env.NUXT_OAUTH_WORKOS_CONNECTION_ID
27
32
*/
28
33
connectionId ?: string
29
34
/**
30
- * WorkOS OAuth screen hint
35
+ * WorkOS OAuth screen hint *not required
31
36
* @default 'sign-in'
32
37
*/
33
38
screenHint ?: 'sign-in' | 'sign-up'
@@ -37,6 +42,7 @@ export interface OAuthWorkOSConfig {
37
42
*/
38
43
redirectURL ?: string
39
44
}
45
+
40
46
export interface OAuthWorkOSUser {
41
47
object : 'user'
42
48
id : string
@@ -74,7 +80,7 @@ export function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }: OA
74
80
return handleMissingConfiguration ( event , 'workos' , [ 'clientId' , 'clientSecret' ] , onError )
75
81
}
76
82
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 )
78
84
const redirectURL = config . redirectURL || getOAuthRedirectURL ( event )
79
85
80
86
if ( query . error ) {
@@ -89,16 +95,14 @@ export function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }: OA
89
95
response_type : 'code' ,
90
96
provider : 'authkit' ,
91
97
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 ,
95
102
} ) ,
96
103
)
97
104
}
98
105
99
- const ip_address = getRequestIP ( event )
100
- const user_agent = getRequestHeader ( event , 'user-agent' )
101
-
102
106
const authenticateResponse : OAuthWorkOSAuthenticateResponse = await requestAccessToken ( 'https://api.workos.com/user_management/authenticate' , {
103
107
headers : {
104
108
'Content-Type' : 'application/json' ,
@@ -108,8 +112,8 @@ export function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }: OA
108
112
client_id : config . clientId ,
109
113
client_secret : config . clientSecret ,
110
114
redirect_uri : redirectURL ,
111
- ip_address,
112
- user_agent,
115
+ ip_address : getRequestIP ( event ) ,
116
+ user_agent : getRequestHeader ( event , 'user-agent' ) ,
113
117
code : query . code ,
114
118
} ,
115
119
} )
0 commit comments