instance.tokens/v1
A multisite host checks an API token one of its instances issued. pocketone login and pocketone clone sign in
to the instance (its oauth/v1) and get the instance's own token. Where the host, not the instance, answers deploy/v1
and remote/v1, the host checks that token with this contract, so signing in works the same way on every host.
A service contract (tokens.go), one provider, on the host's scope. It holds no auth of its own: the host decides what an instance token may do there (for example, only the instance's superusers may deploy).
Use
tk, ok := tokensv1.Contract.In(host.Scope) // after the host's seal
res, err := tk.Verify(ctx, tokensv1.Input{Instance: id, Token: token})
switch {
case errors.Is(err, tokensv1.ErrNoInstance): // not one of this runtime's instances, or it has no API tokens
case err != nil: // the instance failed to start: not a refusal
case !res.Valid: // res.Reason: "invalid" or "expired"
default: // res.Grant: the owner (collection, id) and scopes, as api-tokens/v1 says
}
The answer is api-tokens.verify/v1's Result. A token the instance didn't
issue is Valid: false, never an error, so a host can tell a refused token from an instance that won't start.
Verifying may start an instance that isn't running.
Provide
A runtime that can reach inside its instances provides it on the host scope (ProvideIn): look up the instance's
app and ask its api-tokens/v1 (Verify), mapping apitokensv1.ErrInvalid and ErrExpired to Valid: false.
A runtime that can't (stock PocketBase images) doesn't provide it.
Extensions
| Extension | |
|---|---|
| pocker | provides |
License
MIT
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.