You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Added failover if server does not recognize the auth header
This commit is contained in:
@@ -385,6 +385,8 @@ module.exports.MatrixHttpApi.prototype = {
|
|||||||
if (!queryParams) {
|
if (!queryParams) {
|
||||||
queryParams = {};
|
queryParams = {};
|
||||||
}
|
}
|
||||||
|
if (this.authorization_header_supported === undefined ||
|
||||||
|
this.authorization_header_supported) {
|
||||||
if (isFinite(opts)) {
|
if (isFinite(opts)) {
|
||||||
// opts used to be localTimeoutMs
|
// opts used to be localTimeoutMs
|
||||||
opts = {
|
opts = {
|
||||||
@@ -400,6 +402,11 @@ module.exports.MatrixHttpApi.prototype = {
|
|||||||
if (!opts.headers.Authorization) {
|
if (!opts.headers.Authorization) {
|
||||||
opts.headers.Authorization = "Bearer " + this.opts.accessToken;
|
opts.headers.Authorization = "Bearer " + this.opts.accessToken;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (!queryParams.access_token) {
|
||||||
|
queryParams.access_token = this.opts.accessToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const request_promise = this.request(
|
const request_promise = this.request(
|
||||||
callback, method, path, queryParams, data, opts,
|
callback, method, path, queryParams, data, opts,
|
||||||
@@ -408,6 +415,11 @@ module.exports.MatrixHttpApi.prototype = {
|
|||||||
const self = this;
|
const self = this;
|
||||||
request_promise.catch(function(err) {
|
request_promise.catch(function(err) {
|
||||||
if (err.errcode == 'M_UNKNOWN_TOKEN') {
|
if (err.errcode == 'M_UNKNOWN_TOKEN') {
|
||||||
|
if (self.authorization_header_supported === undefined) {
|
||||||
|
self.authorization_header_supported = false;
|
||||||
|
return self.authedRequest(
|
||||||
|
callback, method, path, queryParams, data, opts);
|
||||||
|
}
|
||||||
self.event_emitter.emit("Session.logged_out");
|
self.event_emitter.emit("Session.logged_out");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user