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

# Sign users in with OAuth

> Let people connect their Linkvite account to your app with OAuth 2.1: authorization code with PKCE, rotating refresh tokens and scopes.

Use OAuth when people other than you will sign in to your app: a browser extension, a desktop or mobile app, a web app or an integration. Users approve the [scopes](https://docs.linkvite.io/developers/scopes.md) you ask for on a Linkvite consent screen, and you get an access token limited to them.

| | |
| - | - |
| Authorization endpoint | `https://api.linkvite.io/v1/oauth/authorize` |
| Token endpoint | `https://api.linkvite.io/v1/oauth/token` |
| Revocation endpoint | `https://api.linkvite.io/v1/oauth/revoke` |
| Server metadata | `https://api.linkvite.io/.well-known/oauth-authorization-server` |
| Grant types | `authorization_code` (with PKCE `S256`), `refresh_token` |
| Client authentication | `none` (public clients), `client_secret_basic`, `client_secret_post` |

## Register your app

In the web app, go to **Settings** → **Developers** and create an app. Choose:

* **Public** for apps that can't keep a secret (extensions, desktop, mobile, single-page apps). They authenticate with PKCE alone.
* **Confidential** for apps with a server that can keep a client secret.

Add your redirect URI and the scopes the app may request. You get a client ID (and a secret for confidential apps).

> [!TIP]
>
> Clients that support Client ID Metadata Documents (such as MCP clients) can skip registration: their `client_id` is an `https://` URL that serves their metadata.

## Authorization code flow with PKCE

**1. Send the user to Linkvite**

Create a PKCE verifier and its `S256` challenge, plus a random `state`. Store both, then redirect to the authorization endpoint:

```text theme={null}
https://api.linkvite.io/v1/oauth/authorize
  ?response_type=code
  &client_id=<client_id>
  &redirect_uri=<redirect_uri>
  &scope=bookmarks:read bookmarks:write
  &state=<state>
  &code_challenge=<challenge>
  &code_challenge_method=S256
```

Add `prompt=consent` to always show the consent screen.

**2. Handle the redirect**

After the user selects **Allow**, Linkvite redirects to your `redirect_uri` with `code` and `state`. Check that `state` matches what you stored.

**3. Exchange the code for tokens**

```bash theme={null}
curl -X POST https://api.linkvite.io/v1/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d grant_type=authorization_code \
  -d code=<code> \
  -d redirect_uri=<redirect_uri> \
  -d client_id=<client_id> \
  -d code_verifier=<verifier>
```

```json theme={null}
{
  "access_token": "...",
  "token_type": "Bearer",
  "expires_in": 1800,
  "refresh_token": "...",
  "scope": "bookmarks:read bookmarks:write"
}
```

A code works once; replaying it revokes the tokens it produced.

**4. Call the API**

Send the access token as `Authorization: Bearer <access_token>`.

With the SDKs:

```javascript JavaScript theme={null}
import {Linkvite, oauth} from '@linkvite/js';

const pkce = await oauth.createPkce();
const state = await oauth.createState();
location.href = oauth.authorizeUrl({
	clientId: CLIENT_ID,
	redirectUri: REDIRECT_URI,
	scope: 'bookmarks:read bookmarks:write',
	state,
	codeChallenge: pkce.challenge,
});

// on the redirect back, after checking state:
const tokens = await oauth.exchangeCode({
	clientId: CLIENT_ID,
	redirectUri: REDIRECT_URI,
	code,
	codeVerifier: pkce.verifier,
});
const linkvite = new Linkvite({token: tokens.access_token});
```

```go Go theme={null}
// golang.org/x/oauth2
conf := &oauth2.Config{
	ClientID:    clientID,
	RedirectURL: redirectURI,
	Scopes:      []string{"bookmarks:read", "bookmarks:write"},
	Endpoint:    oauth2.Endpoint{AuthURL: linkvite.AuthURL, TokenURL: linkvite.TokenURL},
}
verifier := oauth2.GenerateVerifier()
url := conf.AuthCodeURL(state, oauth2.S256ChallengeOption(verifier))

// on the redirect back:
tok, err := conf.Exchange(ctx, code, oauth2.VerifierOption(verifier))
client, err := linkvite.NewClient("", linkvite.WithHTTPClient(conf.Client(ctx, tok)))
```

## Refresh tokens

Access tokens are short-lived (`expires_in`, in seconds). Get a new one with the refresh token:

```bash theme={null}
curl -X POST https://api.linkvite.io/v1/oauth/token \
  -d grant_type=refresh_token \
  -d refresh_token=<refresh_token> \
  -d client_id=<client_id>
```

> [!WARNING]
>
> Refresh tokens rotate: each one works once, and the response contains a new one. Store it before using the new access token. Presenting a refresh token that was already used revokes the whole session, and the user has to sign in again. Make sure only one refresh runs at a time (the JavaScript SDK's `oauth.singleFlightRefresher` does this).

## Sign out

Revoke the refresh token (or the access token) when the user signs out:

```bash theme={null}
curl -X POST https://api.linkvite.io/v1/oauth/revoke \
  -d token=<refresh_token> \
  -d client_id=<client_id>
```

Users can also revoke your app's access from their Linkvite settings.

## Resource indicators

Tokens are bound to one resource (RFC 8707): the REST API (`https://api.linkvite.io`) or the [MCP server](https://docs.linkvite.io/developers/mcp.md) (`https://api.linkvite.io/mcp`). Pass `resource` on the authorization and token requests to choose; without it, the token is for the REST API.

## Errors

The token and revocation endpoints return standard OAuth errors:

```json theme={null}
{
  "error": "invalid_grant",
  "error_description": "..."
}
```


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