fixing
Some checks failed
CI/CD / test (push) Failing after 15s
CI/CD / deploy (push) Has been skipped

This commit is contained in:
Untone 2024-02-17 14:36:31 +03:00
parent e4da92d7ee
commit c374f54307
4 changed files with 10 additions and 7 deletions

BIN
bun.lockb Executable file

Binary file not shown.

View File

@ -5,7 +5,7 @@ import {
ValidateJWTTokenInput, ValidateJWTTokenInput,
ValidateJWTTokenResponse, ValidateJWTTokenResponse,
} from '@authorizerdev/authorizer-js' } from '@authorizerdev/authorizer-js'
import { Server, onAuthenticatePayload } from '@hocuspocus/server' import Server, { onAuthenticatePayload } from '@hocuspocus/server';
const authorizer = new Authorizer({ const authorizer = new Authorizer({
clientID: process.env.AUTHORIZER_CLIENT_ID, clientID: process.env.AUTHORIZER_CLIENT_ID,
@ -16,10 +16,9 @@ const authorizer = new Authorizer({
const server = await Server.configure({ const server = await Server.configure({
port: 4242, port: 4242,
async onConnect({ connection }) { async onConnect({ connection }) {
connection.requiresAuthentication = false // FIXME connection.requiresAuthentication = true
}, },
async onAuthenticate(data: onAuthenticatePayload) { async onAuthenticate(data: onAuthenticatePayload) {
// Danger! This wont be called for that connection attempt.
if (data.requestHeaders) { if (data.requestHeaders) {
const params: ValidateJWTTokenInput = { const params: ValidateJWTTokenInput = {
@ -32,8 +31,13 @@ const server = await Server.configure({
if (response?.data?.is_valid) { if (response?.data?.is_valid) {
const { sub: user, allowed_roles: roles } = response.data.claims const { sub: user, allowed_roles: roles } = response.data.claims
console.debug(`user_id: ${user} roles: ${roles}`) console.debug(`user_id: ${user} roles: ${roles}`)
return {
id: user,
roles
}
} else { } else {
console.debug('no valid auth token presented') console.error('no valid auth token presented')
throw new Error("Not authorized!")
} }
} }
} }

View File

@ -5,7 +5,7 @@
"main": "index.ts", "main": "index.ts",
"type": "module", "type": "module",
"scripts": { "scripts": {
"lint": "npx @biomejs/biome check --apply-unsafe .", "fix": "npx @biomejs/biome check --fix --apply-unsafe .",
"start": "npx tsc index.ts" "start": "npx tsc index.ts"
}, },
"repository": { "repository": {

View File

@ -1,5 +1,4 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es2017", "target": "es2017",
"lib": ["es2022", "dom"], "lib": ["es2022", "dom"],