Revert "feat(api): return (Self, AuthenticationResult) from authenticate"
This reverts commit c8c371230f.
This commit is contained in:
@@ -34,10 +34,10 @@ impl JellyfinClient {
|
||||
username: impl AsRef<str>,
|
||||
password: impl AsRef<str>,
|
||||
config: JellyfinConfig,
|
||||
) -> Result<(Self, jellyfin::AuthenticationResult)> {
|
||||
) -> Result<Self> {
|
||||
let url = format!("{}/Users/AuthenticateByName", config.server_url);
|
||||
let client = reqwest::Client::new();
|
||||
let auth_result = client
|
||||
let token = client
|
||||
.post(url)
|
||||
.json(&jellyfin::AuthenticateUserByName {
|
||||
username: Some(username.as_ref().to_string()),
|
||||
@@ -47,14 +47,10 @@ impl JellyfinClient {
|
||||
.await?
|
||||
.error_for_status()?
|
||||
.json::<jellyfin::AuthenticationResult>()
|
||||
.await?;
|
||||
|
||||
let token = auth_result
|
||||
.await?
|
||||
.access_token
|
||||
.as_ref()
|
||||
.ok_or_else(|| std::io::Error::other("No field access_token in auth response"))?;
|
||||
|
||||
Ok((Self::pre_authenticated(token, config)?, auth_result))
|
||||
Self::pre_authenticated(token, config)
|
||||
}
|
||||
|
||||
pub fn pre_authenticated(token: impl AsRef<str>, config: JellyfinConfig) -> Result<Self> {
|
||||
@@ -84,10 +80,6 @@ impl JellyfinClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn access_token(&self) -> Option<&str> {
|
||||
self.access_token.as_deref().map(|s| &*s)
|
||||
}
|
||||
|
||||
pub async fn save_token(&self, path: impl AsRef<std::path::Path>) -> std::io::Result<()> {
|
||||
if let Some(token) = &self.access_token {
|
||||
tokio::fs::write(path, &**token).await
|
||||
@@ -112,19 +104,6 @@ impl JellyfinClient {
|
||||
self.access_token = Some(token.as_ref().into());
|
||||
}
|
||||
|
||||
pub async fn me(&self) -> Result<jellyfin::UserDto> {
|
||||
let uri = "Users/Me";
|
||||
let text = self
|
||||
.request_builder(reqwest::Method::GET, uri)
|
||||
.send()
|
||||
.await?
|
||||
.error_for_status()?
|
||||
.text()
|
||||
.await?;
|
||||
let out: jellyfin::UserDto = serde_json::from_str(&text)?;
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub fn request_builder(
|
||||
&self,
|
||||
method: reqwest::Method,
|
||||
|
||||
Reference in New Issue
Block a user