import { Issuer , Client , custom } from "openid-client" ; import { InternalOptions } from "src/lib/types" ; /**
 * NOTE: We can add auto discovery of the provider's endpoint
 * that requires only one endpoint to be specified by the user.
 * Check out `Issuer.discover`
 *
 * Client supporting OAuth 2.x and OIDC
 */ export async function openidClient ( options ) { const provider = options . provider ; if ( provider . httpOptions ) custom . setHttpOptionsDefaults ( provider . httpOptions ) ; let issuer ; if ( provider . wellKnown ) { issuer = await Issuer . discover ( provider . wellKnown ) ; } else { issuer = new Issuer ( { issuer : provider . issuer as string , authorization_endpoint : provider . authorization ?. url ?? provider . authorization , token_endpoint : provider . token ?. url ?? provider . token , userinfo_endpoint : provider . userinfo ?. url ?? provider . userinfo , } ) ; } const client = new issuer . Client ( { client_id : provider . clientId as string , client_secret : provider . clientSecret as string , redirect_uris : [ provider . callbackUrl ] , ... provider . client , } , provider . jwks ) ; client [ custom . clock_tolerance ] = 10 ; return client ; }