add revoke

This commit is contained in:
2025-09-17 16:51:35 -03:00
parent 207231cff6
commit b2303fc60a
18 changed files with 411 additions and 140 deletions

View File

@@ -1,4 +1,5 @@
export const OK = 200
export const FOUND = 302
export const BAD_REQUEST = 400
export const UNAUTHORIZED = 401
export const INTERNAL_SERVER = 500

View File

@@ -1,12 +1,13 @@
import {
type RouteConfig,
index,
layout,
route
route,
type RouteConfig
} from '@react-router/dev/routes'
export default [
layout('routes/layout.tsx', [index('routes/index.tsx')]),
route('/authorize', 'routes/authorize.ts'),
route('/token', 'routes/token.ts')
route('/token', 'routes/token.ts'),
route('/revoke', 'routes/revoke.ts')
] satisfies RouteConfig

View File

@@ -30,15 +30,6 @@ export async function loader({ request, context }: Route.LoaderArgs) {
redirect: 'manual'
})
// if (r.status === httpStatus.BAD_REQUEST) {
// return new Response(null, {
// status: httpStatus.FOUND,
// headers: {
// Location: redirect.toString()
// }
// })
// }
if (r.status === httpStatus.FOUND) {
return new Response(await r.text(), {
status: r.status,
@@ -46,9 +37,17 @@ export async function loader({ request, context }: Route.LoaderArgs) {
})
}
return Response.json(await r.json(), {
status: r.status,
headers: r.headers
console.log('Issuer response', {
json: await r.json(),
headers: r.headers,
status: r.status
})
return new Response(null, {
status: httpStatus.FOUND,
headers: {
Location: redirect.toString()
}
})
} catch {
return new Response(null, { status: httpStatus.INTERNAL_SERVER })

View File

@@ -0,0 +1,17 @@
import type { Route } from './+types'
export async function action({ request, context }: Route.ActionArgs) {
const issuerUrl = new URL('/revoke', context.cloudflare.env.ISSUER_URL)
const r = await fetch(issuerUrl.toString(), {
method: request.method,
headers: request.headers,
body: await request.text()
})
// console.log(await r.text(), r)
return new Response(await r.text(), {
status: r.status,
headers: r.headers
})
}