add token
This commit is contained in:
39
id.saladeaula.digital/client/app/routes/authorize.ts
Normal file
39
id.saladeaula.digital/client/app/routes/authorize.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { parse } from 'cookie'
|
||||||
|
|
||||||
|
import type { Route } from './+types/authorize'
|
||||||
|
|
||||||
|
export async function loader({ request, context }: Route.LoaderArgs) {
|
||||||
|
const cookies = parse(request.headers.get('Cookie') || '')
|
||||||
|
const url = new URL(request.url)
|
||||||
|
const issuerUrl = new URL('/authorize', context.cloudflare.env.ISSUER_URL)
|
||||||
|
issuerUrl.search = url.search
|
||||||
|
|
||||||
|
if (!cookies.session_id) {
|
||||||
|
url.pathname = '/'
|
||||||
|
|
||||||
|
return new Response(null, {
|
||||||
|
status: 302,
|
||||||
|
headers: {
|
||||||
|
Location: url.toString()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const r = await fetch(issuerUrl.toString(), {
|
||||||
|
method: 'GET',
|
||||||
|
headers: new Headers([
|
||||||
|
['Content-Type', 'application/json'],
|
||||||
|
['Cookie', request.headers.get('Cookie') as string]
|
||||||
|
]),
|
||||||
|
redirect: 'manual'
|
||||||
|
})
|
||||||
|
|
||||||
|
return new Response(await r.text(), {
|
||||||
|
status: r.status,
|
||||||
|
headers: r.headers
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
return new Response(null, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
15
id.saladeaula.digital/client/app/routes/token.ts
Normal file
15
id.saladeaula.digital/client/app/routes/token.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import type { Route } from './+types/token'
|
||||||
|
|
||||||
|
export async function action({ request, context }: Route.ActionArgs) {
|
||||||
|
const issuerUrl = new URL('/token', context.cloudflare.env.ISSUER_URL)
|
||||||
|
const r = await fetch(issuerUrl.toString(), {
|
||||||
|
method: request.method,
|
||||||
|
headers: request.headers,
|
||||||
|
body: await request.text()
|
||||||
|
})
|
||||||
|
|
||||||
|
return new Response(await r.text(), {
|
||||||
|
status: r.status,
|
||||||
|
headers: r.headers
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user