Skip to content

Commit

Permalink
Don't send authorization header to origins other than jellyfin server
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkukla committed Nov 5, 2024
1 parent b25cd3b commit 2bd932d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions app/src/main/java/org/jellyfin/mobile/app/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jellyfin.mobile.app

import android.content.Context
import androidx.core.net.toUri
import coil.ImageLoader
import com.google.android.exoplayer2.ext.cronet.CronetDataSource
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
Expand Down Expand Up @@ -110,17 +111,23 @@ val applicationModule = module {
val dataSourceFactory = DefaultDataSource.Factory(context, baseDataSourceFactory)

// Add authorization header. This is needed as we don't pass the
// access token in the url for Android Auto.
// access token in the URL for Android Auto.
ResolvingDataSource.Factory(dataSourceFactory) { dataSpec: DataSpec ->
val authorizationHeaderString = AuthorizationHeaderBuilder.buildHeader(
clientName = apiClient.clientInfo.name,
clientVersion = apiClient.clientInfo.version,
deviceId = apiClient.deviceInfo.id,
deviceName = apiClient.deviceInfo.name,
accessToken = apiClient.accessToken,
)

dataSpec.withRequestHeaders(hashMapOf("Authorization" to authorizationHeaderString))
// Only send authorization header if URI matches the jellyfin server
val baseUrlAuthority = apiClient.baseUrl?.toUri()?.authority

if (dataSpec.uri.authority == baseUrlAuthority) {
val authorizationHeaderString = AuthorizationHeaderBuilder.buildHeader(
clientName = apiClient.clientInfo.name,
clientVersion = apiClient.clientInfo.version,
deviceId = apiClient.deviceInfo.id,
deviceName = apiClient.deviceInfo.name,
accessToken = apiClient.accessToken,
)

dataSpec.withRequestHeaders(hashMapOf("Authorization" to authorizationHeaderString))
} else
dataSpec
}
}
single<MediaSource.Factory> {
Expand Down

0 comments on commit 2bd932d

Please sign in to comment.