1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Use correct /v3 prefix for /refresh (#3016)

* Add tests to ensure /v3/refresh is called + automatic /v1 retry

* Request /refresh with v3 prefix, and quietly fall back to v1

* Add tests checking re-raising errors

* Update spec/unit/login.spec.ts

* Update comment

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>

---------

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
David Lee
2023-06-03 10:56:12 -04:00
committed by GitHub
parent dfb079a76f
commit 258f157ebc
2 changed files with 111 additions and 10 deletions

View File

@@ -7689,16 +7689,27 @@ 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
},
);
// First try with the (specced) /v3/ prefix.
// However, before Synapse 1.72.0, Synapse incorrectly required a /v1/ prefix, so we fall
// back to that if the request fails, for backwards compatibility.
return performRefreshRequestWithPrefix(ClientPrefix.V3).catch((e) => {
if (e.errcode === "M_UNRECOGNIZED") {
return performRefreshRequestWithPrefix(ClientPrefix.V1);
}
throw e;
});
}
/**