Skip to Content
Credentials

Credentials

Every credential in Foir has one job. This page says which one to use where, and what each may do.

CredentialUsed byWhere it lives
Publishable keyWebsites and appsIn the open: in your page or your app bundle
Server keyA server that renders your app’s pagesOn that server. Never in a browser
SessionPeople, and agents acting for themPer person, for as long as they are signed in
Operation tokenLogic that Foir runs for youPer run, for minutes
Admin keyUnattended machines: sync jobs, pipelines, toolsOn a machine you control. It expires

An app holds a publishable key. If a server renders its pages, that server holds a server key. An app never holds an admin key.

The three kinds of key

You choose a key’s kind when you make it. Foir then holds the key to what that kind may hold and give, and refuses anything else by name, saying why.

A key has two lists:

  • What it holds. For a publishable or a server key this is the most a signed-in person may do through it. For an admin key it is what the key itself does.
  • What it gives. What anyone who comes through the key may do with nobody signed in.

Nothing is filled in for you. A key made with nothing on its second list gives a visitor nothing, and Foir tells you so when you make it.

Publishable key

A publishable key sits in a web page or an app, where anyone can read it. So it gives a visitor only what is safe to give everyone: reads you choose, one model a visitor may submit into, one operation a visitor may run.

It may hold more than it gives. A write on a publishable key is a ceiling: someone who signs in through the key may write if their role says so, and a visitor still may not.

It begins foir_pub_. It never expires.

Server key

A server key is for a server that renders your pages: a Next.js or Remix server, a Hydrogen storefront, a worker at the edge. It gives a visitor exactly what a publishable key gives. It holds two things more:

  • visitors:forward: it may say who and where the visitor it is calling for is, so that limits and location apply to your visitor and not to your server. See A server rendering your pages.
  • records:read.all: it may be the ceiling for a signed-in person whose role lets them read every owner’s records, such as your own staff. It never gives this to a visitor.

A server key is shown once, and is refused from a browser. It begins foir_srv_. It never expires, so a lapsed key cannot take your pages down. Revoke it when you no longer want it.

Admin key

An admin key is a machine’s own: a warehouse sync, an indexer, a deploy pipeline, a script. It does what it holds, and it may hold management permissions that no app’s key may.

  • Nobody signs in through an admin key. A sign-in, a token refresh, or a person’s token sent beside an admin key is refused. It gives nobody anything.
  • It expires. An admin key is given 90 days unless you say otherwise, and a year at most. Renew it before then and it keeps its secret, so nothing that holds it needs changing. Its owner and your workspace’s managers are told 14 days and 3 days before it lapses.
  • Use one per system, holding the least that system needs.

It is shown once, and is refused from a browser. It begins foir_adm_.

# A key for a nightly sync, for 90 days foir api-keys create --name "Warehouse sync" --kind admin --grants records:read.all,files:read.all # Keep it for another 90 days, with the same secret foir api-keys renew <key-id>

An admin key for the workspace itself

An admin key is bound to one project unless you ask for the workspace’s own. A workspace’s admin key is bound to no project. It holds only what acts on the workspace itself: its projects, its keys, its usage, its hooks, installing apps, and exporting a project.

foir api-keys create --name "Provisioner" --kind admin --workspace --grants projects:write,usage:read

A workspace’s key cannot be used on the data API, which serves projects. To export a project with one, name the project: foir export postgres --project-id <id>, or project_id on the agent’s export tool. The project has to be one of the key’s own workspace, and a project that has been deleted is not exported until it is reactivated.

Sessions

A person signs in and acts as themselves, holding what their role gives. That is true of your app’s users, of your team in the console, of an agent connected over OAuth, and of the CLI after foir login.

In your app, a signed-in person comes through a key: the publishable key in your page, or your server key. The key is the ceiling and their role decides what they may do under it. The console sends the person’s token alone, with no key.

Operations

Logic that must not run in a browser is an operation. You write a function, host it anywhere, and Foir is the only thing that can call it. Each run carries a token that holds only what the operation declares, for minutes.

When you think you need a server

You almost never need a server that holds a key and forwards requests.

You want toUse
Read published contentA publishable key that gives the read
Let a visitor send a formA publishable key that gives records:create:<model>
Let people sign in and see their own thingsSessions, through your publishable key
Charge a card, call another service, check stockAn operation
Let your staff see every user’s records in your appA role that gives records:read.all, signed in through your server key
Render pages on a serverA server key on that server
Sync to a warehouse, index, back upAn admin key on that machine

If you find yourself putting an admin key in an app’s server so that it can do something privileged for a user, that privileged thing is an operation.

What a refusal means

You are toldWhat to do
Nobody signs in through an admin keySign people in with your publishable key, or with your server key from the server that renders your pages
A publishable key may not be minted to give somethingThat thing is not safe to give everyone. Give it to a role and let people sign in, or do it in an operation
An admin key gives nobody anythingLeave its second list empty. People come through a publishable or a server key
A key made at a workspace cannot be used on the data APIUse a project’s key for a project’s data
This key never expiresOnly an admin key takes an expiry. Revoke a publishable or a server key when you no longer want it
An app client was given an admin keyBuild the client from your publishable key, or your server key on the server that renders your pages

A key that leaks

A server key and an admin key have a format a scanner can recognise without asking Foir: the prefix, 43 characters, and a 6 character checksum. One pattern finds them: foir_(srv|adm)_[0-9A-Za-z]{49}.

When a secret scanner reports one to Foir, the key is revoked at once. Nobody is asked first, because what matters is how long the key keeps working after it is seen. Whoever made the key and the workspace’s managers are emailed which key it was and where it was found, and the revocation is in the audit trail with the same.

  • A key that was rotated. If the secret found is the one the key was rotated from, that secret is retired and the key keeps working under the one it has now.
  • A key that had expired or was switched off is revoked too. Renewing a key or switching it back on keeps its secret, and a secret that is in the open must not come back.
  • A publishable key is public by design. It is left as it is.

Then take the secret out of wherever it was found: it stays in a repository’s history after the file is changed. If you know a key is out before a scanner does, revoke it yourself.

Last updated on