fixing
This commit is contained in:
parent
e4da92d7ee
commit
c374f54307
12
index.ts
12
index.ts
|
@ -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 won’t 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!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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": {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
{
|
{
|
||||||
|
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es2017",
|
"target": "es2017",
|
||||||
"lib": ["es2022", "dom"],
|
"lib": ["es2022", "dom"],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user