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

# Generate SDK Token

Create a SDK token for a user. This token is required for client-side operations and OAuth portal access.

## OAuth Portal Integration

The SDK token is essential for using Tapti's OAuth Portal, where your users can securely connect their social media accounts:

```typescript theme={null}
// 1. Generate SDK token on your backend
const sdkToken = await tapti.user().createSDKToken(userId);

// 2. Redirect user to OAuth Portal
const oauthUrl = `https://oauth.tapti.dev?sdk_token=${sdkToken}`;
// Optional: Specify platform to skip selection screen
const youtubeOauthUrl = `https://oauth.tapti.dev?sdk_token=${sdkToken}&platform=youtube`;
```

<Note>
  The OAuth Portal provides a secure, branded experience for connecting social media accounts without requiring you to
  implement complex OAuth flows.
</Note>

## Security Considerations

<Warning>
  * SDK tokens are short-lived and user-specific - Never store tokens in localStorage or expose them in client-side
    source code - Generate new tokens just before redirecting to the OAuth Portal - Include only necessary platform
    permissions
</Warning>

## Related Resources

<CardGroup cols={2}>
  <Card title="OAuth Portal" icon="key" href="/docs/concepts/oauth-portal">
    Learn more about the OAuth Portal
  </Card>

  <Card title="SDK Tokens" icon="key" href="/docs/guides/sdk-tokens">
    Understanding SDK tokens
  </Card>
</CardGroup>


## OpenAPI

````yaml post /users/{id}/sdk-token
openapi: 3.0.0
info:
  title: Tapti Fusion API
  description: API for the Tapti Fusion platform
  version: '1.0'
  contact: {}
servers:
  - url: https://api.tapti.ai
security: []
tags: []
paths:
  /users/{id}/sdk-token:
    post:
      tags:
        - Users
      summary: Create a SDK token for a user
      operationId: createSdkTokenForUser
      parameters:
        - name: id
          required: true
          in: path
          description: The ID of the user to create a SDK token for
          schema:
            example: 690739f7-3e1b-4ceb-a439-23bd9c7ae573
      requestBody:
        required: true
        description: The SDK token to create
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSDKTokenDto'
      responses:
        '200':
          description: SDK token created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateSDKTokenResponseAdminDto'
        '400':
          description: Bad Request
        '500':
          description: Internal Server Error
components:
  schemas:
    CreateSDKTokenDto:
      type: object
      properties:
        user_platforms:
          type: array
          description: The platforms to create the SDK token for
          example:
            - YOUTUBE
            - TIKTOK
          items:
            type: string
            enum:
              - YOUTUBE
              - TIKTOK
              - INSTAGRAM
              - INSTAPRO
              - FACEBOOK
              - X
              - LINKEDIN
        enabled_scopes:
          type: array
          description: The scopes to create the SDK token for
          example:
            - PROFILE_READ
          items:
            type: string
            enum:
              - PROFILE_READ
              - PROFILE_WRITE
              - CONTENT_READ
              - CONTENT_WRITE
              - ANALYTICS_READ
              - COMMENTS_READ
              - COMMENTS_WRITE
        callback_url:
          type: string
          description: The callback URL to send the account connection response to
          example: https://your-app.com/api/oauth/callback
        redirect_url:
          type: string
          description: >-
            The redirect URL to redirect the user after successful
            authentication
          example: https://your-app.com/dashboard/accounts
      required:
        - user_platforms
        - enabled_scopes
        - callback_url
        - redirect_url
    CreateSDKTokenResponseAdminDto:
      type: object
      properties:
        oauth_portal_url:
          type: string
          description: The OAuth portal URL to redirect the user to
          example: >-
            https://oauth-portal.example.com?sdk_token=8pjBUEbqcA3bkKEBTmZ2WsduYwMH6UU23byRiU2rs.........&origin=https://your-app.com/dashboard/accounts
      required:
        - oauth_portal_url

````