Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authorization header #434

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
options.credentials = 'same-origin';

fetch(url, options)
.then((response) => {

Check warning on line 69 in src/apiClient.js

View workflow job for this annotation

GitHub Actions / Lint

Each then() should return a value or throw
clearTimeout(timeout);
resolve(response);
})
Expand Down Expand Up @@ -176,9 +176,7 @@
}

if (values.length) {
const auth = `MediaBrowser ${values.join(', ')}`;
//headers.Authorization = auth;
headers['X-Emby-Authorization'] = auth;
headers['Authorization'] = `MediaBrowser ${values.join(', ')}`;
thornbill marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -280,7 +278,7 @@
}
} else {
onFetchFail(instance, request.url, response);
return Promise.reject(response);

Check warning on line 281 in src/apiClient.js

View workflow job for this annotation

GitHub Actions / Lint

Expected throw instead of Promise.reject
}
})
.catch((error) => {
Expand All @@ -296,7 +294,7 @@

const previousServerAddress = instance.serverAddress();

return tryReconnect(instance)

Check warning on line 297 in src/apiClient.js

View workflow job for this annotation

GitHub Actions / Lint

Avoid nesting promises

Check warning on line 297 in src/apiClient.js

View workflow job for this annotation

GitHub Actions / Lint

Avoid nesting promises
.then(() => {
console.log('Reconnect succeeded');
request.url = request.url.replace(previousServerAddress, instance.serverAddress());
Expand Down Expand Up @@ -352,12 +350,12 @@
}
} else {
onFetchFail(instance, request.url, response);
return Promise.reject(response);

Check warning on line 353 in src/apiClient.js

View workflow job for this annotation

GitHub Actions / Lint

Expected throw instead of Promise.reject
}
})
.catch((error) => {
onFetchFail(instance, request.url, {});
return Promise.reject(error);

Check warning on line 358 in src/apiClient.js

View workflow job for this annotation

GitHub Actions / Lint

Expected throw instead of Promise.reject
});
}

Expand Down Expand Up @@ -444,7 +442,7 @@
if (userId && instance.accessToken()) {
user = getCachedUser(instance, userId);
if (user) {
return Promise.resolve(user);

Check warning on line 445 in src/apiClient.js

View workflow job for this annotation

GitHub Actions / Lint

Avoid wrapping return values in Promise.resolve
}
}
}
Expand Down Expand Up @@ -487,7 +485,7 @@
return this.ajax({
type: 'POST',
url
}).then(done, done);

Check warning on line 488 in src/apiClient.js

View workflow job for this annotation

GitHub Actions / Lint

Avoid calling back inside of a promise
}

done();
Expand Down Expand Up @@ -525,8 +523,8 @@
resolve(result);
};

if (this.onAuthenticated) {

Check warning on line 526 in src/apiClient.js

View workflow job for this annotation

GitHub Actions / Lint

Each then() should return a value or throw
this.onAuthenticated(this, result).then(afterOnAuthenticated);

Check warning on line 527 in src/apiClient.js

View workflow job for this annotation

GitHub Actions / Lint

Expected catch() or return
} else {
afterOnAuthenticated();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/apiClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('ApiClient class', () => {
client.setRequestHeaders(headers);
}).not.toThrow(Error);
expect(headers).toStrictEqual({
'X-Emby-Authorization':
'Authorization':
'MediaBrowser Client="Jellyfin Web", Device="Firefox", DeviceId="TW96aWxsYS81LjAgKFgxMTsgTGludXggeDg2XzY0OyBydjo3NC4wKSBHZWNrby8yMDEwMDEwMSBGaXJlZm94Lzc0LjB8MTU4NDkwMTA5OTY3NQ11", Version="10.5.0"'
});
});
Expand Down
Loading