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,6 +385,8 @@ module.exports.MatrixHttpApi.prototype = {
if (!queryParams) {
queryParams = {};
}
if (this.authorization_header_supported === undefined ||
this.authorization_header_supported) {
if (isFinite(opts)) {
// opts used to be localTimeoutMs
opts = {
@@ -400,6 +402,11 @@ module.exports.MatrixHttpApi.prototype = {
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(
callback, method, path, queryParams, data, opts,
@@ -408,6 +415,11 @@ module.exports.MatrixHttpApi.prototype = {
const self = this;
request_promise.catch(function(err) {
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");
}
});