I’m just really trying to figure out how serverless expects the Cognito auth token to be passed with a websockets connection.
I have an authoriser lambda on my websocket paths:
connectionHandler:
handler: handler.connectionHandler
events:
- websocket:
route: $connect
authorizer:
arn: ${self:provider.environment.authoriserArn}
- websocket:
route: $disconnect
authorizer:
arn: ${self:provider.environment.authoriserArn}
I was wondering how I actually pass the token from the client over the connection in order for the auth to trigger correctly.
I’ve tried with rxjs
websocket and with protocols, but not really sure how the authoriser should handle the request (I cannot see any token in the params passed in). I don’t believe we can add headers to websockets:
private setupWebsockets(token: string) {
const subjectConfig: WebSocketSubjectConfig<any> = {
url: 'wss://abcd1234.execute-api.ap-southeast-1.amazonaws.com/pre',
protocol: [
`${token}`
]
};
this.subject = webSocket(subjectConfig);
this.subject.subscribe(
(msg) => console.log('message received: ' + msg),
(err) => console.error(err),
() => console.log('complete')
);
}
Cheers