Websocket authorzation handler - return something that isn't `500`?
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- aws, typescript
- 领域
- api, authentication, backend
调研方向
先从 $connect 的 WebSocket 配置和 authHandler 的返回值入手,然后将它们与 API Gateway authorizer 契约以及观察到的 500 响应进行比较。对于此示例,确定支持的错误状态和 TypeScript handler 类型,并为缺少 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 分钟
- 30 天内合并 PR
- 3
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 ·