fix(auth): improve login resilience with headerless fallback authentication (#814)

adds fallback to authenticate without headers to ensure and improve resilience across different
browsers and client configurations.
This commit is contained in:
Fallenbagel
2024-06-13 14:16:07 +05:00
committed by GitHub
parent b5a069901a
commit a9741fa36d

View File

@@ -126,25 +126,31 @@ class JellyfinAPI extends ExternalAPI {
Password?: string,
ClientIP?: string
): Promise<JellyfinLoginResponse> {
try {
const headers = ClientIP
? {
'X-Forwarded-For': ClientIP,
}
: {};
const authenticate = async (useHeaders: boolean) => {
const headers =
useHeaders && ClientIP ? { 'X-Forwarded-For': ClientIP } : {};
const authResponse = await this.post<JellyfinLoginResponse>(
return this.post<JellyfinLoginResponse>(
'/Users/AuthenticateByName',
{
Username: Username,
Username,
Pw: Password,
},
{
headers: headers,
}
{ headers }
);
};
return authResponse;
try {
return await authenticate(true);
} catch (e) {
logger.debug(`Failed to authenticate with headers: ${e.message}`, {
label: 'Jellyfin API',
ip: ClientIP,
});
}
try {
return await authenticate(false);
} catch (e) {
const status = e.response?.status;