1.0.2
Some checks failed
deploy / deploy (push) Failing after 32s

This commit is contained in:
2024-02-05 14:49:38 +03:00
parent 0c484f71dc
commit 8940086e96
7 changed files with 291 additions and 21 deletions

View File

@@ -1,17 +1,22 @@
import { Server, onAuthenticatePayload } from "@hocuspocus/server";
import { ApiResponse, Authorizer, ConfigType, ValidateJWTTokenInput, ValidateJWTTokenResponse } from '@authorizerdev/authorizer-js';
import {
ApiResponse,
Authorizer,
ConfigType,
ValidateJWTTokenInput,
ValidateJWTTokenResponse,
} from '@authorizerdev/authorizer-js'
import { Server, onAuthenticatePayload } from '@hocuspocus/server'
const authorizer = new Authorizer({
clientID: process.env.AUTHORIZER_CLIENT_ID,
authorizerURL: 'https://auth.discours.io',
redirectURL: 'https://testing.discours.io'
} as ConfigType);
redirectURL: 'https://testing.discours.io',
} as ConfigType)
const server = await Server.configure({
port: 4242,
async onConnect({ connection }) {
connection.requiresAuthentication = false; // FIXME
connection.requiresAuthentication = false // FIXME
},
async onAuthenticate(data: onAuthenticatePayload) {
// Danger! This wont be called for that connection attempt.
@@ -24,7 +29,7 @@ const server = await Server.configure({
if (params.token) {
// NOTE: ожидаем, что клиент отправит токен
const response: ApiResponse<ValidateJWTTokenResponse> = await authorizer.validateJWTToken(params)
if(response?.data?.is_valid) {
if (response?.data?.is_valid) {
const { sub: user, allowed_roles: roles } = response.data.claims
console.debug(`user_id: ${user} roles: ${roles}`)
} else {
@@ -32,8 +37,7 @@ const server = await Server.configure({
}
}
}
},
}).listen();
}).listen()
server.listen();
server.listen()