Skip to content

Commit

Permalink
[Jellyfin] Force X-Emby-Authorization header to avoid SQL exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Schaka committed Feb 15, 2024
1 parent bf5245f commit ff5d3f0
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.schaka.janitorr.jellyfin

import com.fasterxml.jackson.databind.ObjectMapper
import com.github.schaka.janitorr.jellyfin.api.User
import feign.Feign
import feign.jackson.JacksonDecoder
import feign.jackson.JacksonEncoder
Expand Down Expand Up @@ -49,12 +48,8 @@ class JellyfinClientConfig {
}

@Bean
fun jellyfinUserClient(properties: JellyfinProperties, mapper: ObjectMapper, jellyfin: JellyfinClient): JellyfinUserClient {

val user = jellyfin.listUsers().filter { it.Name.lowercase() == properties.username.lowercase() }.firstOrNull()
?: throw IllegalArgumentException("User ${properties.username} not found")

val userInfo = getUserInfo(properties, user)
fun jellyfinUserClient(properties: JellyfinProperties, mapper: ObjectMapper): JellyfinUserClient {
val userInfo = getUserInfo(properties)
val accessToken = userInfo.body?.get("AccessToken")

log.info("Logged in to Jellyfin as {} {}", properties.username, accessToken)
Expand All @@ -69,12 +64,15 @@ class JellyfinClientConfig {
.target(JellyfinUserClient::class.java, properties.url)
}

private fun getUserInfo(properties: JellyfinProperties, user: User): ResponseEntity<Map<*, *>> {
private fun getUserInfo(properties: JellyfinProperties): ResponseEntity<Map<*, *>> {
val login = RestTemplate()
val map = LinkedMultiValueMap<String, Any>()
map.add("Username", properties.username)
map.add("Pw", properties.password)
val headers = HttpHeaders()
headers.set("X-Emby-Authorization", "MediaBrowser Client=\"Janitorr\", Device=\"Spring Boot\", DeviceId=\"Janitorr-Device-Id\", Version=\"1.0\"")
headers.set(CONTENT_TYPE, APPLICATION_JSON_VALUE)
return login.postForEntity("${properties.url}/Users/${user.Id}/Authenticate?pw={password}", HttpEntity(map, headers), Map::class.java, properties.password)
return login.postForEntity("${properties.url}/Users/AuthenticateByName", HttpEntity(map, headers), Map::class.java)
}

}

0 comments on commit ff5d3f0

Please sign in to comment.