Capital/server/api/well-known/openid-configuration.ts
2025-03-22 23:55:44 +08:00

20 lines
687 B
TypeScript

import { defineEventHandler } from 'h3'
export default defineEventHandler(async () => {
const config = useRuntimeConfig();
const siteUrl = config.public.siteUrl
const resp = await fetch(`${config.public.solarNetworkApi}/cgi/id/well-known/openid-configuration`)
const out: Record<string, any> = await resp.json()
out['authorization_endpoint'] = `${siteUrl}/auth/authorize`
out['jwks_uri'] = `${siteUrl}/.well-known/jwks`
for (const [k, v] of Object.entries(out)) {
if (typeof v === 'string' && v.startsWith('https://id.solsynth.dev/api')) {
out[k] = v.replace('https://id.solsynth.dev/api', `${config.public.solarNetworkApi}/cgi/id`)
}
}
return out
})