diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..bcccb5b Binary files /dev/null and b/bun.lockb differ diff --git a/index.ts b/index.ts index fa5814e..d0b27d6 100644 --- a/index.ts +++ b/index.ts @@ -5,7 +5,7 @@ import { ValidateJWTTokenInput, ValidateJWTTokenResponse, } from '@authorizerdev/authorizer-js' -import { Server, onAuthenticatePayload } from '@hocuspocus/server' +import Server, { onAuthenticatePayload } from '@hocuspocus/server'; const authorizer = new Authorizer({ clientID: process.env.AUTHORIZER_CLIENT_ID, @@ -16,10 +16,9 @@ const authorizer = new Authorizer({ const server = await Server.configure({ port: 4242, async onConnect({ connection }) { - connection.requiresAuthentication = false // FIXME + connection.requiresAuthentication = true }, async onAuthenticate(data: onAuthenticatePayload) { - // Danger! This won’t be called for that connection attempt. if (data.requestHeaders) { const params: ValidateJWTTokenInput = { @@ -32,8 +31,13 @@ const server = await Server.configure({ if (response?.data?.is_valid) { const { sub: user, allowed_roles: roles } = response.data.claims console.debug(`user_id: ${user} roles: ${roles}`) + return { + id: user, + roles + } } else { - console.debug('no valid auth token presented') + console.error('no valid auth token presented') + throw new Error("Not authorized!") } } } diff --git a/package.json b/package.json index 4f02384..1f7c70c 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.ts", "type": "module", "scripts": { - "lint": "npx @biomejs/biome check --apply-unsafe .", + "fix": "npx @biomejs/biome check --fix --apply-unsafe .", "start": "npx tsc index.ts" }, "repository": { diff --git a/tsconfig.json b/tsconfig.json index 4a163f5..10bf43c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,4 @@ { - "compilerOptions": { "target": "es2017", "lib": ["es2022", "dom"], @@ -7,4 +6,4 @@ "moduleResolution": "NodeNext", "module": "NodeNext" } -} \ No newline at end of file +}