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

# Attach

> Pre-associate an OAuth flow with an existing Stytch User

The attach method wraps the [attach](/docs/api-reference/consumer/api/oauth/attach) OAuth API endpoint and generates an OAuth Attach Token to pre-associate an OAuth flow with an existing Stytch User. You must have an active Stytch session to use this endpoint. Pass the returned `oauth_attach_token` to the same provider's OAuth Start endpoint to treat this OAuth flow as a login for that user instead of a signup

## Parameters

<ParamField body="provider" type="string" required>
  The OAuth provider's name.
</ParamField>

## Response

<ResponseField name="oauth_attach_token" type="string">
  A single-use token for connecting the Stytch User selection from an OAuth Attach request to the corresponding OAuth Start request.
</ResponseField>

<ResponseField name="request_id" type="string">
  Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we
  may ask for this value to help identify a specific API call when helping you debug an issue.
</ResponseField>

<ResponseField name="status_code" type="number">
  The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values
  equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
</ResponseField>

<Panel>
  <RequestExample>
    ```jsx theme={null}
    import { useCallback } from 'react';
    import { useStytch } from '@stytch/react';

    export const OAuthAttach = () => {
    const stytch = useStytch();

    const trigger = useCallback(() => {
      stytch.oauth.attach('microsoft').then((resp) => {
        stytch.oauth.microsoft.start({
          oauth_attach_token: resp.oauth_attach_token,
        });
      });
    }, [stytch]);

    return <button onClick={trigger}>OAuth Attach</button>;
    };
    ```
  </RequestExample>

  <ResponseExample>
    ```json 200 theme={null}
    {
        "status_code": 200,
        "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
        "oauth_attach_token": "...",
    }
    ```

    ```json 429 theme={null}
    {
      "status_code": 429,
      "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
      "error_type": "too_many_requests",
      "error_message": "Too many requests have been made.",
      "error_url": "https://stytch.com/docs/api/errors/429"
    }
    ```

    ```json 500 theme={null}
    {
      "status_code": 500,
      "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
      "error_type": "internal_server_error",
      "error_message": "Oops, something seems to have gone wrong, please reach out to support@stytch.com to let us know what went wrong.",
      "error_url": "https://stytch.com/docs/api/errors/500"
    }
    ```
  </ResponseExample>
</Panel>
