> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getlurk.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sign-in for your app's users

> Let the people who sign in to your app see their balance and receipts and send a few events, with your own sign-in provider and no project key in the browser.

Your app's users read their own balance and receipts, and send their own events, from the browser or phone, with the sign-in token your app already has from Clerk, Supabase or an OpenID Connect (OIDC) provider. No project key goes in the app.

## Before you start

* **Your role.** You are an owner or admin of the project. Only they can set this up.
* **The API address.** `https://api.getlurk.com`, for projects made at app.getlurk.com, both Staging and Production. The project ID picks the project.
* **Your project ID**, `prj_…`. It is not a secret. The **Project ID** under Settings > Project is the project's short name (`organization/project`), not `prj_…`. Choose the project in the dashboard's project switcher, and the address bar shows `?project=prj_…`.

```bash title="Set these once" theme={null}
export LURK_API_URL="https://api.getlurk.com"
export LURK_PROJECT="prj_your_project_id"
```

## 1. Add your provider

In the dashboard, open Settings, the **Sign-in** tab, and choose **Add a provider**. Give it a **Name**, choose the provider and fill in:

> [tab] Supabase
>
> * **Project ref**: the 20 letters in `https://<ref>.supabase.co`.
>
> The project must sign with asymmetric keys, not the legacy shared secret. [Supabase](https://docs.getlurk.com/end-user-auth/supabase.md)

> [tab] Clerk
>
> * **Frontend API address**: as Clerk shows it, such as `https://clerk.your-site.com`.
> * **Allowed origins**: the sites your app signs in from, one per line.
>
> Lurk takes Clerk's session token, not a JWT template token. [Clerk](https://docs.getlurk.com/end-user-auth/clerk.md)

> [tab] OpenID Connect
>
> * **Issuer**: the exact `iss` of your ID tokens. A trailing slash counts.
> * **Key address**: where the provider publishes its public keys (JWKS).
> * **Audiences**: your app's client ID.
> * **Algorithms**: `RS256`, `ES256` or both.
>
> Tested with Auth0. Others are expected to work but are not tested. [Other providers](https://docs.getlurk.com/end-user-auth/other-providers.md)

Leave **Longest token** at 3,600 seconds unless your tokens last longer (Auth0's: 36,000). It is saved paused.

## 2. Turn it on

On the provider's row:

1. **Check keys.**
2. **Test a token.** Sign in to your app and paste the token your provider gave it. A good token answers **The token is good**, then **This provider is paused**, as it should before step 3. OpenID Connect needs this to turn on. Clerk tokens last 60 seconds: paste a fresh one.
3. **Turn on.** It shows after a key check in the last 24 hours (and, for OpenID Connect, a `verified` token test).
4. **Allow new people.** In **Events people's apps may send**, tick **Limit new people**, set **New people an hour**, and choose **Save**.

> [!WARNING]
>
> Until step 4 is saved, a person who has never signed in is refused: the call answers 401 `invalid_key`, and the token test says **Sign-in with a provider isn’t switched on yet**.

## 3. Make your first call

Send the person's token as the bearer and your project ID in `Lurk-Project`.

```bash title="Read the signed-in person's balances" theme={null}
curl "$LURK_API_URL/v1/client/balances" \
  -H "Authorization: Bearer $SIGN_IN_TOKEN" \
  -H "Lurk-Project: $LURK_PROJECT"
```

Success is a 200. A new person's list is usually empty, and that is correct:

```json theme={null}
{ "balances": [] }
```

A new person holds a unit only if it starts above 0 (`starts_at`) or a rule gives it.

## 4. Send an event

1. **Allow the name.** In **Events people's apps may send**, add it with **Allow an event**, such as `checkin.scanned`, and choose **Save**. A name not on the list is refused. Saving is refused while a live or paused rule hears the name with no `source` condition.
2. **Send it** with a unique `idempotency_key` in the body. It is required.

```bash title="Send an event for the signed-in person" theme={null}
curl -X POST "$LURK_API_URL/v1/client/events" \
  -H "Authorization: Bearer $SIGN_IN_TOKEN" \
  -H "Lurk-Project: $LURK_PROJECT" \
  -H "Content-Type: application/json" \
  -d '{"event": "checkin.scanned", "idempotency_key": "chk-8841"}'
```

The `Idempotency-Key` header is optional here. If you send it, Lurk uses its key instead of the body's.

**Retrying.** After a network failure, a 429 or a 503, resend with the same key: nothing is counted twice. [Idempotency and retries](https://docs.getlurk.com/guides/idempotency-and-retries.md)

The answer lists the receipts the event made. A device's event is `untrusted`: only a rule with `source: any` hears it ([Rules](https://docs.getlurk.com/rules.md)).

## If it fails

Run **Test a token** first: the API never says why it refused a token. Every code: [Troubleshooting](https://docs.getlurk.com/end-user-auth/troubleshooting.md).

| You see | It means |
| - | - |
| 401 `invalid_key` | The token was refused, the provider is off, a new person came before step 4, or the project ID is not one this API knows. |
| 403 `forbidden` | The person is blocked, or the event name is not allowed. |
| 409 `idempotency_conflict` | The key was used with a different request. |
| 422 `validation_failed` | `Lurk-Project` is missing or is not a project ID, or a field is wrong. The error names it. |
| 429 `rate_limited` | A limit or cap, or too many new people this hour. Wait `Retry-After` seconds. |
| 503 `unavailable` | The sign-in could not be checked now. Wait `Retry-After` seconds and retry. |

## What a device may do

A signed-in person's app is a **device**. It does the calls above for its own person and nothing else: Lurk reads the person from the token, and a device cannot name another person, change rules, units or settings, or give or take units.

## What you trust, and what a device cannot choose

You trust the provider you add. A device cannot choose it.

* See [Add a trusted issuer](https://docs.getlurk.com/end-user-auth/add-a-trusted-issuer.md) for setup, approval and address rules.
* Lurk fetches the signing keys itself, from that address. A key or certificate inside a token is never used.
* A device sends only the token. A bearer that starts with `lurk_`, or one next to a member's session cookie, is refused.
* Lurk checks the token on every request but does not ask the provider whether the session is alive, so a token works until it expires. Block a person to stop them sooner. See [Linking people](https://docs.getlurk.com/end-user-auth/linking-people.md#block-and-unblock).

Lurk verifies that your provider's tenant signed the token, not who owns the tenant. Two Lurk projects that trust the same tenant accept each other's tokens. Use one provider project for each boundary you want to keep.

## What the token must carry

* A signature from a key in the issuer's key set, with `RS256` or `ES256`, and a `kid` in the header.
* An `iss` equal to the issuer you saved, exactly.
* One audience in `aud`, one you listed. Clerk is the exception: see [Clerk](https://docs.getlurk.com/end-user-auth/clerk.md).
* An `exp` and an `iat`, with `exp` minus `iat` no longer than the issuer's longest token (60 to 86,400 seconds, 3,600 by default). Lurk allows 30 seconds of clock difference.
* A `sub` of 1 to 255 printable ASCII characters, with no spaces.
* Whatever the provider's own rules add. Anonymous sessions are refused.

Lurk keeps only the issuer and the `sub`. It never reads a name, an email or a picture from the token.

## Reference

[Clerk](https://docs.getlurk.com/end-user-auth/clerk.md), [Supabase](https://docs.getlurk.com/end-user-auth/supabase.md), [other providers](https://docs.getlurk.com/end-user-auth/other-providers.md), [Client API](https://docs.getlurk.com/end-user-auth/client-api.md) (headers, CORS, limits), [Linking people](https://docs.getlurk.com/end-user-auth/linking-people.md) (merges, blocks, the token test) and [Troubleshooting](https://docs.getlurk.com/end-user-auth/troubleshooting.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.