fix: jellyfin integration does not allow username password auth (#1714)

This commit is contained in:
Manuel
2024-12-18 14:10:58 +01:00
committed by GitHub
parent 1baa9fc74c
commit 63a7be35a4
2 changed files with 23 additions and 5 deletions

View File

@@ -29,6 +29,10 @@ export abstract class Integration {
return secret.value;
}
protected hasSecretValue(kind: IntegrationSecretKind) {
return this.integration.decryptedSecrets.some((secret) => secret.kind === kind);
}
protected url(path: `/${string}`, queryParams?: Record<string, string | Date | number | boolean>) {
const baseUrl = removeTrailingSlash(this.integration.url);
const url = new URL(`${baseUrl}${path}`);

View File

@@ -18,13 +18,13 @@ export class JellyfinIntegration extends Integration {
});
public async testConnectionAsync(): Promise<void> {
const api = this.getApi();
const api = await this.getApiAsync();
const systemApi = getSystemApi(api);
await systemApi.getPingSystem();
}
public async getCurrentSessionsAsync(): Promise<StreamSession[]> {
const api = this.getApi();
const api = await this.getApiAsync();
const sessionApi = getSessionApi(api);
const sessions = await sessionApi.getSessions();
@@ -59,8 +59,22 @@ export class JellyfinIntegration extends Integration {
});
}
private getApi() {
const apiKey = this.getSecretValue("apiKey");
return this.jellyfin.createApi(this.url("/").toString(), apiKey);
/**
* Constructs an ApiClient synchronously with an ApiKey or asynchronously
* with a username and password.
* @returns An instance of Api that has been authenticated
*/
private async getApiAsync() {
if (this.hasSecretValue("apiKey")) {
const apiKey = this.getSecretValue("apiKey");
return this.jellyfin.createApi(this.url("/").toString(), apiKey);
}
const apiClient = this.jellyfin.createApi(this.url("/").toString());
// Authentication state is stored internally in the Api class, so now
// requests that require authentication can be made normally.
// see https://typescript-sdk.jellyfin.org/#usage
await apiClient.authenticateUserByName(this.getSecretValue("username"), this.getSecretValue("password"));
return apiClient;
}
}