Websocket authorzation handler - return something that isn't `500`?
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- aws, typescript
- 領域
- api, authentication, backend
調査の方向性
$connect の WebSocket 設定と authHandler の戻り値から始め、それらを API Gateway の authorizer コントラクトおよび観測された 500 レスポンスと比較します。この例でサポートされるエラーステータスと TypeScript のハンドラー型が確定し、secret を含まないリクエストに対する再現可能なチェックがあれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Question / help needed
I'm trying to get authorization working before connecting to websockets, which works, but I'm struggling to return an error message that isn't 500.
I've managed to make an auth handler, like so:
connectHandler: {
handler: 'handler.connectHandler',
events: [
{
"websocket": {
route: "$connect",
authorizer: {
name: "authHandler",
identitySource: [
// No identity source, leave it up to the handler
],
},
},
},
],
environment: {
// ..
},
},
Any my authHandler:
export const authHandler = async (event, _context) => {
console.log('🔑 Auth request received', event.requestContext)
const token = event.headers.Authorization ?? event.queryStringParameters.Authorization;
console.log('Token:', token)
if (token !== 'secret') {
return {
statusCode: 401,
}
}
return {
"principalId": "user",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "execute-api:Invoke",
"Effect": "Allow",
"Resource": event.methodArn
}
]
}
};
}
Questions:
-
what should I return in case of an error? Any request to my websocket-server that doesn't have the
secretheader/querystring returns500right now, and I'd prefer it to return a4xxstatus code. -
what is the correct type for the authorization handler? I'm using
APIGatewayProxyHandleron the other fn handlers which gives me nice inline errors.How my other handlers look like, which gives me pleasant TypeScript-errors when I do something wrong
```tsexport const connectHandler: APIGatewayProxyHandler = async (event, _context) => {
const connectionId = event.requestContext.connectionId!console.log('➕ Adding connection ', connectionId)
await client.query('INSERT INTO "public"."Connection"("id") VALUES($1) RETURNING *', [connectionId])
return {
statusCode: 200,
body: '',
};
}</details>
- 主要言語
- JavaScript
- スター
- 11.5k
- フォーク
- 4.4k
- 平均マージ
- 2時間 55分
- マージ済み PR(30日)
- 3
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
serverless/examples のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
serverless/examples#404 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
serverless/examples#809 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 30/100
serverless/examples#793 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 20/100
serverless/examples#784 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
serverless/examples#782 ·
serverless/examples の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
mksglu/context-mode#1200 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
neondatabase/website#5944 ·
-
module: core
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
bigbluebutton/bigbluebutton#25849 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
jaegertracing/jaeger-ui#4506 ·