@@ -6,6 +6,7 @@ import { defu } from 'defu'
6
6
import { useRuntimeConfig } from '#imports'
7
7
import type { OAuthConfig } from '#auth-utils'
8
8
import { type OAuthChecks , checks } from '../../utils/security'
9
+ import { validateConfig } from '../../utils/config'
9
10
10
11
export interface OAuthOidcConfig {
11
12
/**
@@ -78,35 +79,13 @@ export interface OAuthOidcConfig {
78
79
checks ?: OAuthChecks [ ]
79
80
}
80
81
81
- function validateConfig ( config : any ) {
82
- const requiredConfigKeys = [ 'clientId' , 'clientSecret' , 'authorizationUrl' , 'tokenUrl' , 'userinfoUrl' , 'redirectUri' , 'responseType' ]
83
- const missingConfigKeys : string [ ] = [ ]
84
- requiredConfigKeys . forEach ( key => {
85
- if ( ! config [ key ] ) {
86
- missingConfigKeys . push ( key )
87
- }
88
- } )
89
- if ( missingConfigKeys . length ) {
90
- const error = createError ( {
91
- statusCode : 500 ,
92
- message : `Missing config keys: ${ missingConfigKeys . join ( ', ' ) } `
93
- } )
94
-
95
- return {
96
- valid : false ,
97
- error
98
- }
99
- }
100
- return { valid : true }
101
- }
102
-
103
82
export function oidcEventHandler ( { config, onSuccess, onError } : OAuthConfig < OAuthOidcConfig > ) {
104
83
return eventHandler ( async ( event : H3Event ) => {
105
84
// @ts -ignore
106
85
config = defu ( config , useRuntimeConfig ( event ) . oauth ?. oidc ) as OAuthOidcConfig
107
86
const { code } = getQuery ( event )
108
87
109
- const validationResult = validateConfig ( config )
88
+ const validationResult = validateConfig ( config , [ 'clientId' , 'clientSecret' , 'authorizationUrl' , 'tokenUrl' , 'userinfoUrl' , 'redirectUri' , 'responseType' ] )
110
89
111
90
if ( ! validationResult . valid && validationResult . error ) {
112
91
if ( ! onError ) throw validationResult . error
0 commit comments