Skip to content

Commit 7f01cb3

Browse files
committed
fix: Use Authorization header for sending access_token to WebSocket API
1 parent 3825819 commit 7f01cb3

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/adapters/clients.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ export function createStreamingAPIClient(
8080
{
8181
constructorParameters: [
8282
config.resolvePath("/api/v1/streaming"),
83-
config.getProtocols(),
83+
[],
84+
{
85+
headers: config.getHeaders(),
86+
},
8487
],
8588
implementation: props.implementation,
8689
maxAttempts: config.getMaxAttempts(),

src/adapters/config/web-socket-config.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe("WebSocketConfigImpl", () => {
3131
);
3232
});
3333

34-
it("creates websocket protocol with token when supported", () => {
34+
it("creates websocket header with token when supported", () => {
3535
const config = new WebSocketConfigImpl(
3636
{
3737
streamingApiUrl: "wss://mastodon.social",
@@ -40,10 +40,10 @@ describe("WebSocketConfigImpl", () => {
4040
new SerializerNativeImpl(),
4141
);
4242

43-
expect(config.getProtocols()).toEqual(["token"]);
43+
expect(config.getHeaders()).toEqual({ Authorization: "token" });
4444
});
4545

46-
it("creates websocket protocol without token when not supported", () => {
46+
it("creates websocket header without token when not supported", () => {
4747
const config = new WebSocketConfigImpl(
4848
{
4949
streamingApiUrl: "wss://mastodon.social",
@@ -53,7 +53,7 @@ describe("WebSocketConfigImpl", () => {
5353
new SerializerNativeImpl(),
5454
);
5555

56-
expect(config.getProtocols()).toEqual([]);
56+
expect(config.getHeaders()).toEqual({});
5757
});
5858

5959
it("gets max attempts with retry true", () => {

src/adapters/config/web-socket-config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ export class WebSocketConfigImpl implements WebSocketConfig {
5959
private readonly serializer: Serializer,
6060
) {}
6161

62-
getProtocols(protocols: readonly string[] = []): string[] {
62+
getHeaders(): Record<string, string> {
6363
if (
6464
this.props.useInsecureAccessToken ||
6565
this.props.accessToken == undefined
6666
) {
67-
return [...protocols];
67+
return {};
6868
}
6969

70-
return [this.props.accessToken, ...protocols];
70+
return {
71+
Authorization: this.props.accessToken,
72+
};
7173
}
7274

7375
resolvePath(path: string, params: Record<string, unknown> = {}): URL {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface WebSocketConfig {
22
getMaxAttempts(): number;
3-
getProtocols(protocols?: readonly string[]): string[];
3+
getHeaders(): Record<string, string>;
44
resolvePath(path: string, params?: Record<string, unknown>): URL;
55
}

0 commit comments

Comments
 (0)