jellyfin-tools/jellyfin-year-review/internal/auth/provider.go
jellyfin-year-review/internal/auth/provider.goRaw
1package auth
2
3import (
4 "context"
5
6 "reelreview/internal/source"
7)
8
9// Provider isolates serving from the mechanism that validates account credentials.
10// Token is a server-only Jellyfin token or an offline credential revision.
11type Provider interface {
12 Login(context.Context, string, string, string) (source.Account, string, error)
13 Validate(context.Context, Session) (source.Account, error)
14 Logout(context.Context, Session) error
15 Mode() string
16}
17
18type Online struct{ Jellyfin *source.Jellyfin }
19
20func (p Online) Mode() string { return "jellyfin" }
21func (p Online) Login(ctx context.Context, name, password, device string) (source.Account, string, error) {
22 return p.Jellyfin.Login(ctx, name, password, device)
23}
24func (p Online) Validate(ctx context.Context, s Session) (source.Account, error) {
25 return p.Jellyfin.Me(ctx, s.Token, s.Device)
26}
27func (p Online) Logout(ctx context.Context, s Session) error {
28 return p.Jellyfin.Call(ctx, "POST", "/Sessions/Logout", s.Token, s.Device, nil, nil)
29}