Unauthorized
The call came without a valid publishable key or API token, or with a key that may not be used from there.
Unauthorized means the key or token sent with the call is missing, wrong or not allowed here. The status is 401, or 403 when a valid key is used where it may not be.
Issue
A call fails before any handler runs, with one of these messages.
| Message | Status | Cause |
|---|---|---|
a valid publishable key (luna-key header or ?key=) or API token is required |
401 | No key or token, or one that is wrong, revoked or expired |
this route takes an API token (Authorization: Bearer) |
401 | The HTTP route accepts API tokens only |
this route takes a publishable key (luna-key header or ?key=) or an API token |
401 | The HTTP route needs a credential and none was valid |
this publishable key isn't allowed from this origin |
403 | The key was made with --origin, and the page’s origin is not one of them |
this publishable key can't call this route |
403 | The key was made with --type, and the route belongs to another type |
this publishable key has been revoked |
On a connection | An open connection’s key was revoked |
Cause
Luna checks the credential of every call from outside, except HTTP routes open to anyone. A publishable key goes in the luna-key header or the key query parameter. An API token goes in Authorization: Bearer.
Unauthorized differs from a refusal by your own onBeforeConnect hook. That one also answers 403, but its code is the one your hook chose. It also differs from NotFound, which a key made with --type gets for a handler of a type it was not made for.
Solution
Do not retry with the same credential. Send a valid one.
curl -X POST "$LUNA_URL/List/groceries/all" -H "luna-key: $LUNA_KEY"
- Check
LUNA_KEYagainst the keys of the environment withluna keys list. - Make a new key with
luna keys create, with the origins and types the app needs. - Use an API token only from your own servers. It reaches private luna types too.
In an app, queued writes pause on this error. Call resumeWrites() once the app has a valid credential again, as Work offline shows.