Keys and sign-in
A request sends its key as a bearer token:
Authorization: Bearer lgsh_live_...Keys start with lgsh_live_. Treat a key like a password: keep it out of source control, browser code and
shared logs. Legesher stores only a hash of each key, so a key cannot be shown again after it is created.
If you lose one, create a new key and revoke the old one.
Create a key on the keys page
Section titled “Create a key on the keys page”- Create an account at app.legesher.io and verify your email address.
- Open Your keys and create a key.
- Copy the key and store it. It is shown once.
How many keys you can hold at once depends on your plan. The keys page also revokes a key.
Sign in from a command line or an editor
Section titled “Sign in from a command line or an editor”A tool can get a key for its user without asking them to copy one, through the OAuth 2.0 device authorization grant (RFC 8628). Starting it needs no key. The endpoints accept JSON or form-encoded bodies.
-
Ask for a code pair.
Terminal window curl -X POST https://api.legesher.io/v1/oauth/device \-H "Content-Type: application/json" -d '{}'{"device_code": "...","user_code": "WDJB-MJHT","verification_uri": "https://app.legesher.io/device","verification_uri_complete": "https://app.legesher.io/device?user_code=WDJB-MJHT","expires_in": 600,"interval": 5} -
Send the user to approve it. Show
user_codeand openverification_uri, or openverification_uri_complete, which fills the code in. The user signs in at app.legesher.io and approves the sign-in. -
Poll for the key. Every
intervalseconds, until the user decides or the code expires:Terminal window curl -X POST https://api.legesher.io/v1/oauth/token \-H "Content-Type: application/json" \-d '{"grant_type": "urn:ietf:params:oauth:grant-type:device_code", "device_code": "<device_code>"}'While the user has not decided, the answer is HTTP 400 with an OAuth error:
errorWhat to do authorization_pendingKeep polling at the same interval. slow_downAdd 5 seconds to the interval, then keep polling. access_deniedThe user declined. Stop. expired_tokenThe code pair expired. Start again from step 1. invalid_grantThe device_codeis unknown or was already used. Start again.invalid_request,unsupported_grant_typeThe request is malformed: check grant_typeanddevice_code.Once the user approves, the answer is the key:
{ "access_token": "lgsh_live_...", "token_type": "bearer" }The
access_tokenis an ordinary API key. It does not expire and there is no refresh token. Store it the way you would store any key.
Check a key
Section titled “Check a key”GET /v1/me describes the key that calls it: the plan, this month’s usage, and the keys in its scope. Key
entries show a short hash prefix, never the key itself.
curl https://api.legesher.io/v1/me -H "Authorization: Bearer $LEGESHER_API_KEY"Revoke a key
Section titled “Revoke a key”Revoke a key on the keys page, or from a tool with POST /v1/oauth/revoke. This is how a command line
signs out:
curl -X POST https://api.legesher.io/v1/oauth/revoke \ -H "Content-Type: application/json" \ -d "{\"token\": \"$LEGESHER_API_KEY\"}"A well-formed request gets 200 with the same body, whether the key was active, already revoked or never
existed (unless it is rate-limited, which answers 429). A revoked key gets 401 from then on.