Closed PhantomPhoton closed 6 months ago
Hello,
This is expected behaviour, but it's also my fault for not documenting the project so much. The expected token is not an API key, but an access token handed by the server.
Here is a snippet extracted from Marmalade's code showing how that token is obtained :
from http import HTTPStatus
from jellyfin_api_client.api.user import authenticate_user_by_name
from jellyfin_api_client.errors import UnexpectedStatus
from jellyfin_api_client.models.authenticate_user_by_name import AuthenticateUserByName
from jellyfin_api_client.models.authentication_result import AuthenticationResult
from src.jellyfin import JellyfinClient, make_device_id
def main(username: str, password: str, base_url: str) -> AuthenticationResult:
device_id = make_device_id()
client = JellyfinClient(base_url=base_url, device_id=device_id)
response = authenticate_user_by_name.sync_detailed(
client=client,
json_body=AuthenticateUserByName(username=username, pw=password),
)
if response.status_code == HTTPStatus.OK:
return response.parsed
if response.status_code == HTTPStatus.UNAUTHORIZED:
raise ValueError("Invalid username or password")
raise UnexpectedStatus(response.status_code, response.content)
def on_success(result: AuthenticationResult) -> None:
print(f"Authenticated {result.user.name}")
print(f"Access token: {result.access_token}")
Don't hesitate to ask me if you have any more questions. I suggest poking around Marmalade's codebase to get more examples of how to use that library, but beware, it's experimental and I've not touched it in a while.
So I'm trying to use this library on JellyFin 10.8.13. I went to Administration -> API Keys and created a new key.
I'm attempting to get a list of items and so here's my code, obviously with BASE_URL and TOKEN being set to valid values.
I'm receiving this result
When looking at the jellyfin logs
Is there a different api key location I need to generate? or am I using the AuthenticatedClient incorrectly?
Thank you very much!