update
This commit is contained in:
@@ -1,6 +0,0 @@
|
|||||||
export const OK = 200
|
|
||||||
export const FOUND = 302
|
|
||||||
export const BAD_REQUEST = 400
|
|
||||||
export const UNAUTHORIZED = 401
|
|
||||||
export const FORBIDDEN = 403
|
|
||||||
export const INTERNAL_SERVER = 500
|
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
import type { Route } from './+types'
|
import type { Route } from './+types'
|
||||||
|
|
||||||
import * as httpStatus from '@/lib/http-status'
|
|
||||||
import { parse } from 'cookie'
|
import { parse } from 'cookie'
|
||||||
|
|
||||||
|
export const OK = 200
|
||||||
|
export const FOUND = 302
|
||||||
|
export const INTERNAL_SERVER_ERROR = 500
|
||||||
|
|
||||||
export async function loader({ request, context }: Route.LoaderArgs) {
|
export async function loader({ request, context }: Route.LoaderArgs) {
|
||||||
const cookies = parse(request.headers.get('Cookie') || '')
|
const cookies = parse(request.headers.get('Cookie') || '')
|
||||||
const url = new URL(request.url)
|
const url = new URL(request.url)
|
||||||
@@ -13,7 +16,7 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
|||||||
|
|
||||||
if (!cookies?.__session) {
|
if (!cookies?.__session) {
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: httpStatus.FOUND,
|
status: FOUND,
|
||||||
headers: {
|
headers: {
|
||||||
Location: loginUrl.toString()
|
Location: loginUrl.toString()
|
||||||
}
|
}
|
||||||
@@ -30,23 +33,23 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
|||||||
redirect: 'manual'
|
redirect: 'manual'
|
||||||
})
|
})
|
||||||
|
|
||||||
if (r.status === httpStatus.FOUND) {
|
if (r.status === FOUND) {
|
||||||
return new Response(await r.text(), {
|
return new Response(await r.text(), {
|
||||||
status: r.status,
|
status: r.status,
|
||||||
headers: r.headers
|
headers: r.headers
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Issuer response', {
|
console.log('Authorize response', {
|
||||||
json: await r.json(),
|
json: await r.json(),
|
||||||
headers: r.headers,
|
headers: r.headers,
|
||||||
status: r.status
|
status: r.status
|
||||||
})
|
})
|
||||||
|
|
||||||
// Deny authorization if user lacks scopes requested by client
|
// Deny authorization if user lacks scopes requested by client
|
||||||
if (r.status === httpStatus.FORBIDDEN) {
|
if (r.status === FOUND) {
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: httpStatus.FOUND,
|
status: r.status,
|
||||||
headers: {
|
headers: {
|
||||||
Location: new URL('/deny', url.origin).toString()
|
Location: new URL('/deny', url.origin).toString()
|
||||||
}
|
}
|
||||||
@@ -54,13 +57,13 @@ export async function loader({ request, context }: Route.LoaderArgs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Response(null, {
|
return new Response(null, {
|
||||||
status: httpStatus.FOUND,
|
status: FOUND,
|
||||||
headers: {
|
headers: {
|
||||||
Location: loginUrl.toString()
|
Location: loginUrl.toString()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
return new Response(null, { status: httpStatus.INTERNAL_SERVER })
|
return new Response(null, { status: INTERNAL_SERVER_ERROR })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import { Button } from '@/components/ui/button'
|
|||||||
import { Checkbox } from '@/components/ui/checkbox'
|
import { Checkbox } from '@/components/ui/checkbox'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import * as httpStatus from '@/lib/http-status'
|
import { FOUND, INTERNAL_SERVER_ERROR, OK } from './authorize'
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
username: z
|
username: z
|
||||||
@@ -60,7 +60,7 @@ export async function action({ request, context }: Route.ActionArgs) {
|
|||||||
body: JSON.stringify(formData)
|
body: JSON.stringify(formData)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (r.status !== httpStatus.OK) {
|
if (r.status !== OK) {
|
||||||
return Response.json(await r.json(), {
|
return Response.json(await r.json(), {
|
||||||
status: r.status,
|
status: r.status,
|
||||||
headers: r.headers
|
headers: r.headers
|
||||||
@@ -74,12 +74,12 @@ export async function action({ request, context }: Route.ActionArgs) {
|
|||||||
headers.set('Location', url.toString())
|
headers.set('Location', url.toString())
|
||||||
|
|
||||||
return new Response(await r.text(), {
|
return new Response(await r.text(), {
|
||||||
status: httpStatus.FOUND,
|
status: FOUND,
|
||||||
headers
|
headers
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
return Response.json({}, { status: httpStatus.INTERNAL_SERVER })
|
return Response.json({}, { status: INTERNAL_SERVER_ERROR })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ async function proxy({
|
|||||||
request,
|
request,
|
||||||
context
|
context
|
||||||
}: Route.ActionArgs): Promise<Response> {
|
}: Route.ActionArgs): Promise<Response> {
|
||||||
console.debug('Request headers', request.headers)
|
|
||||||
|
|
||||||
const url = new URL(request.url)
|
const url = new URL(request.url)
|
||||||
const issuerUrl = new URL(url.pathname, context.cloudflare.env.ISSUER_URL)
|
const issuerUrl = new URL(url.pathname, context.cloudflare.env.ISSUER_URL)
|
||||||
const response = await fetch(issuerUrl.toString(), {
|
const response = await fetch(issuerUrl.toString(), {
|
||||||
@@ -16,8 +14,6 @@ async function proxy({
|
|||||||
headers: request.headers
|
headers: request.headers
|
||||||
})
|
})
|
||||||
|
|
||||||
console.debug('Response headers', response.headers)
|
|
||||||
|
|
||||||
return new Response(await response.text(), {
|
return new Response(await response.text(), {
|
||||||
status: response.status,
|
status: response.status,
|
||||||
headers: response.headers
|
headers: response.headers
|
||||||
|
|||||||
8
id.saladeaula.digital/client/package-lock.json
generated
8
id.saladeaula.digital/client/package-lock.json
generated
@@ -31,6 +31,7 @@
|
|||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/react": "^19.1.2",
|
"@types/react": "^19.1.2",
|
||||||
"@types/react-dom": "^19.1.2",
|
"@types/react-dom": "^19.1.2",
|
||||||
|
"@types/statuses": "^2.0.6",
|
||||||
"tailwindcss": "^4.1.11",
|
"tailwindcss": "^4.1.11",
|
||||||
"tw-animate-css": "^1.3.6",
|
"tw-animate-css": "^1.3.6",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.8.3",
|
||||||
@@ -2668,6 +2669,13 @@
|
|||||||
"@types/react": "^19.0.0"
|
"@types/react": "^19.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/statuses": {
|
||||||
|
"version": "2.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/statuses/-/statuses-2.0.6.tgz",
|
||||||
|
"integrity": "sha512-xMAgYwceFhRA2zY+XbEA7mxYbA093wdiW8Vu6gZPGWy9cmOyU9XesH1tNcEWsKFd5Vzrqx5T3D38PWx1FIIXkA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/acorn": {
|
"node_modules/acorn": {
|
||||||
"version": "8.14.0",
|
"version": "8.14.0",
|
||||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
|
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/react": "^19.1.2",
|
"@types/react": "^19.1.2",
|
||||||
"@types/react-dom": "^19.1.2",
|
"@types/react-dom": "^19.1.2",
|
||||||
|
"@types/statuses": "^2.0.6",
|
||||||
"tailwindcss": "^4.1.11",
|
"tailwindcss": "^4.1.11",
|
||||||
"tw-animate-css": "^1.3.6",
|
"tw-animate-css": "^1.3.6",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.8.3",
|
||||||
|
|||||||
@@ -13,5 +13,6 @@ ISSUER_URL = "https://duiolq49qn25e.cloudfront.net"
|
|||||||
|
|
||||||
[observability.logs]
|
[observability.logs]
|
||||||
enabled = true
|
enabled = true
|
||||||
|
# invocation_logs = true
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,10 @@ Resources:
|
|||||||
CachedMethods: [GET, HEAD]
|
CachedMethods: [GET, HEAD]
|
||||||
ForwardedValues:
|
ForwardedValues:
|
||||||
QueryString: true
|
QueryString: true
|
||||||
|
Headers:
|
||||||
|
- Origin
|
||||||
|
- Access-Control-Request-Method
|
||||||
|
- Access-Control-Request-Headers
|
||||||
Cookies:
|
Cookies:
|
||||||
Forward: all
|
Forward: all
|
||||||
DefaultTTL: 0
|
DefaultTTL: 0
|
||||||
@@ -129,6 +133,8 @@ Resources:
|
|||||||
CachedMethods: [GET, HEAD, OPTIONS]
|
CachedMethods: [GET, HEAD, OPTIONS]
|
||||||
ForwardedValues:
|
ForwardedValues:
|
||||||
QueryString: false
|
QueryString: false
|
||||||
|
Headers:
|
||||||
|
- Origin
|
||||||
DefaultTTL: 3600 # 1 hour
|
DefaultTTL: 3600 # 1 hour
|
||||||
MinTTL: 300 # 5 minutes
|
MinTTL: 300 # 5 minutes
|
||||||
MaxTTL: 86400 # 1 day
|
MaxTTL: 86400 # 1 day
|
||||||
|
|||||||
Reference in New Issue
Block a user