---
title: "Link Provider"
method: POST
path: "/api/v1/me/account/link-provider"
tags: ["account-erasure", "account-linking"]
---

# Link Provider

`POST /api/v1/me/account/link-provider`

## Request

- Base URL: `https://memory.kagura-ai.com` (the document declares no server; this is the origin it was published from)
- URL: `https://memory.kagura-ai.com/api/v1/me/account/link-provider`
- Auth: none declared

Attach a sign-in provider to the current account: start a link-mode
OAuth round-trip. This adds a way to sign in to ONE account; counting two
accounts as one owner is an identity link (``/identity-links``).

The OAuth round-trip *is* the fresh re-auth — there is no password
prompt, which is the locked re-auth contract for OAuth-only users
(edge case 1). The existing ``/auth/{provider}/callback`` reads
``oauth2_state_intent:{state}`` == ``"link"`` and binds the returned
identity to ``oauth2_state_user:{state}`` via ``AccountLinkingService`` —
only when the callback arrives with the session cookie pinned under
``oauth2_state_session:{state}`` here, so the ``authorization_url`` is of
no use to any other browser.

Returns:
    JSON with ``authorization_url`` (frontend redirects to it) and the
    CSRF ``state`` token.

Raises:
    HTTPException(401): no session cookie on the request (``SessionUser``
        is browser-session only, so this is a contradiction).
    HTTPException(500): auth managers not initialised, OAuth2 manager
        missing, or a required env var (GOOGLE_REDIRECT_URI /
        GITHUB_CLIENT_ID) is missing.

## Headers

- `authorization` string, nullable

## Request body

- LinkProviderRequest: Body for POST /me/account/link-provider.
  - `provider` 'google' | 'github', required

## Response `200`

Successful Response

- LinkProviderResponse: Frontend redirects ``window.location`` to ``authorization_url``. Mirrors ``me_oauth.RefreshOAuthResponse``: the OAuth round-trip itself is the fresh re-auth, so no password is ever prompted (edge case 1 — the locked re-auth contract for OAuth-only users).
  - `authorization_url` string, required
  - `state` string, required

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/kagura-ai/apis/kagura-memory-cloud.md) · [All operations](https://skmtc.dev/kagura-ai/apis/kagura-memory-cloud/llms.txt) · [OpenAPI document](https://skmtc.dev/kagura-ai/apis/kagura-memory-cloud/revisions/09f17f5ada29?raw)
