Skip to content

Commit

Permalink
Request /refresh with v3 prefix, and quietly fall back to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
davidisaaclee committed Mar 11, 2023
1 parent d04c205 commit c344a47
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7569,16 +7569,25 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
* @returns Rejects with an error response.
*/
public refreshToken(refreshToken: string): Promise<IRefreshTokenResponse> {
return this.http.authedRequest(
Method.Post,
"/refresh",
undefined,
{ refresh_token: refreshToken },
{
prefix: ClientPrefix.V1,
inhibitLogoutEmit: true, // we don't want to cause logout loops
},
);
const performRefreshRequestWithPrefix = (prefix: ClientPrefix): Promise<IRefreshTokenResponse> =>
this.http.authedRequest(
Method.Post,
"/refresh",
undefined,
{ refresh_token: refreshToken },
{
prefix,
inhibitLogoutEmit: true, // we don't want to cause logout loops
},
);

return performRefreshRequestWithPrefix(ClientPrefix.V3).catch((e) => {
if (e.errcode === "M_UNRECOGNIZED") {
// fall back to the /v1 prefixed API, which was incorrectly used in Synapse before 1.72.0
return performRefreshRequestWithPrefix(ClientPrefix.V1);
}
throw e;
});
}

/**
Expand Down

0 comments on commit c344a47

Please sign in to comment.