Repository navigation
API key authentication for the existing JSON API (revisiting #833) #1352
Replies: 2 comments 2 replies
|
To keep it even simpler, do you think we can make it even easier and you set the API key through an env variable ? If set, it will accept both cookie OR the hard coded API key ? How important is multi user support for your use case ? |
|
Multi-user isn't important for my use case — one automation (an assistant driving search → download) acting as one account. Happy to simplify to your shape. Proposed semantics, so we agree before I rework the PR:
One question: in OIDC/proxy installs the builtin admin may not exist ( If that matches what you had in mind I'll rework #1353 down to that (or open a fresh PR if you'd rather keep the history clean). Per-user keys can be layered on later if anyone actually asks for them; no need to carry that now. |
Uh oh!
There was an error while loading. Please reload this page.
Shelfmark's frontend already drives a complete JSON API under
/api/*, but every route requires a browser session cookie. #833 asked for a public API with bearer tokens and was closed as not planned; I'd like to propose a much narrower version and check whether it fits the project's scope before opening a PR.Proposal: personal API keys as an authentication method, nothing else.
Authorization: Bearer smk_…(orX-Api-Key) and acts exactly as the user who created it — same role, request policy and settings. No scopes.before_requestmiddleware mirrors the existing proxy-auth middleware: it resolves the key into the same session fields every guard already reads, for that request only, with no cookie emitted and any incoming cookie ignored. No existing route or guard changes.smk_-prefixed credentials count as key attempts. A Bearer token that a reverse proxy forwards (oauth2-proxy, Authelia, forwardAuth id tokens) is ignored by the middleware and the request continues with normal session/proxy auth, so existing deployments are unaffected by an upgrade.Why: self-hosters increasingly want to call Shelfmark from scripts, dashboards (Glance), and assistants. Today the only options are scraping, sharing a password, or replaying a cookie.
I have this working on a branch with tests for the store, service, middleware and routes, plus a short docs page: https://github.com/gavinmcfall/shelfmark/tree/feat/api-keys (diff: main...gavinmcfall:shelfmark:feat/api-keys). Happy to open the PR if this is in scope, or to drop it if not.
All reactions