1
0
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:
Krombel
2017-06-27 13:29:08 +02:00
parent d36b8721ca
commit 5da6423fd6

View File

@@ -385,20 +385,27 @@ module.exports.MatrixHttpApi.prototype = {
if (!queryParams) { if (!queryParams) {
queryParams = {}; queryParams = {};
} }
if (isFinite(opts)) { if (this.authorization_header_supported === undefined ||
// opts used to be localTimeoutMs this.authorization_header_supported) {
opts = { if (isFinite(opts)) {
localTimeoutMs: opts, // opts used to be localTimeoutMs
}; opts = {
} localTimeoutMs: opts,
if (!opts) { };
opts = {}; }
} if (!opts) {
if (!opts.headers) { opts = {};
opts.headers = {}; }
} if (!opts.headers) {
if (!opts.headers.Authorization) { opts.headers = {};
opts.headers.Authorization = "Bearer " + this.opts.accessToken; }
if (!opts.headers.Authorization) {
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(
@@ -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");
} }
}); });