-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Navidrome] Clean up base authentication
- Loading branch information
Showing
6 changed files
with
97 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/com/github/schaka/naviseerr/navidrome/NavidromeLogin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.github.schaka.naviseerr.navidrome | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.github.schaka.naviseerr.mediaserver.NavidromeClient | ||
import com.github.schaka.naviseerr.navidrome.NavidromeClientConfig.NavidromeUserInterceptor | ||
import feign.Feign | ||
import feign.jackson.JacksonDecoder | ||
import feign.jackson.JacksonEncoder | ||
import org.springframework.http.HttpEntity | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.HttpHeaders.CONTENT_TYPE | ||
import org.springframework.http.HttpMethod | ||
import org.springframework.http.MediaType.APPLICATION_JSON_VALUE | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.client.RestTemplate | ||
|
||
data class NavidromeUserInfo( | ||
val id: String, | ||
val isAdmin: Boolean, | ||
val lastFMApiKey: String, | ||
val name: String, | ||
val subsonicSalt: String, | ||
val subsonicToken: String, | ||
val token: String, | ||
val username: String, | ||
) | ||
|
||
data class NavidromeSessionUser( | ||
val id: String, | ||
val username: String, | ||
val restClient: NavidromeClient, | ||
|
||
val name: String, | ||
val lastFMApiKey: String, | ||
) | ||
|
||
fun loginToNavidrome(properties: NavidromeProperties): ResponseEntity<NavidromeUserInfo> { | ||
val login = RestTemplate() | ||
val headers = HttpHeaders() | ||
headers.set(CONTENT_TYPE, APPLICATION_JSON_VALUE) | ||
|
||
val loginInfo = """ | ||
{ | ||
"username": "${properties.username}", | ||
"password": "${properties.password}" | ||
} | ||
""".trimIndent() | ||
|
||
return login.exchange("${properties.url}/auth/login", HttpMethod.POST, HttpEntity(loginInfo, headers), NavidromeUserInfo::class.java) | ||
} | ||
|
||
fun newNavidromeClient(properties: NavidromeProperties, mapper: ObjectMapper): NavidromeClient { | ||
return Feign.builder() | ||
.decoder(JacksonDecoder(mapper)) | ||
.encoder(JacksonEncoder(mapper)) | ||
.requestInterceptor(NavidromeUserInterceptor(properties)) | ||
.target(NavidromeClient::class.java, "${properties.url}/api") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html lang="en"> | ||
<body> | ||
<p th:text="'Welcome ' + ${user.username} + '!'">Welcome, logged in user!</p> | ||
</body> | ||
</html> |