implement bearer token authentication #15

Manually merged
Johann150 merged 5 commits from bearer-authentication into main 2022-07-20 13:11:43 +00:00
Showing only changes of commit ff75382af3 - Show all commits

View file

@ -17,10 +17,14 @@ export const initializeStreamingServer = (server: http.Server) => {
ws.on('request', async (request) => {
const q = request.resourceURL.query as ParsedUrlQuery;
// TODO: トークンが間違ってるなどしてauthenticateに失敗したら
// コネクション切断するなりエラーメッセージ返すなりする
// (現状はエラーがキャッチされておらずサーバーのログに流れて邪魔なので)
const [user, app] = await authenticate(request.httpRequest.headers.authorization, q.i);
const [user, app] = await authenticate(request.httpRequest.headers.authorization, q.i)
.catch(err => {
request.reject(403, err.message);
return [];
});
if (typeof user === 'undefined') {
return;
}
if (user?.isSuspended) {
request.reject(400);