@@ -6,6 +6,7 @@ import { defu } from 'defu'
66import { useRuntimeConfig } from '#imports'
77import type { OAuthConfig } from '#auth-utils'
88import { type OAuthChecks , checks } from '../../utils/security'
9+ import { validateConfig } from '../../utils/config'
910
1011export interface OAuthOidcConfig {
1112 /**
@@ -78,35 +79,13 @@ export interface OAuthOidcConfig {
7879 checks ?: OAuthChecks [ ]
7980}
8081
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-
10382export function oidcEventHandler ( { config, onSuccess, onError } : OAuthConfig < OAuthOidcConfig > ) {
10483 return eventHandler ( async ( event : H3Event ) => {
10584 // @ts -ignore
10685 config = defu ( config , useRuntimeConfig ( event ) . oauth ?. oidc ) as OAuthOidcConfig
10786 const { code } = getQuery ( event )
10887
109- const validationResult = validateConfig ( config )
88+ const validationResult = validateConfig ( config , [ 'clientId' , 'clientSecret' , 'authorizationUrl' , 'tokenUrl' , 'userinfoUrl' , 'redirectUri' , 'responseType' ] )
11089
11190 if ( ! validationResult . valid && validationResult . error ) {
11291 if ( ! onError ) throw validationResult . error
0 commit comments