> **Building with AI coding agents?** Install the authstack plugin with one command. This equips your agent with accurate Scalekit implementation patterns.
>
> **Recommended** (the `-y` flags skip prompts, so the command runs without an interactive terminal):
> ```bash
> npx -y @scalekit-inc/cli setup -y
> ```
>
> Global:
> ```bash
> npm install -g @scalekit-inc/cli
> scalekit setup -y
> ```
>
> Supports Claude Code, Cursor, GitHub Copilot, Codex + skills for other Agent Skills-compatible agents in `~/.agents/skills`.
> Skills: integrate-agentkit, implement-saaskit, add-mcp-oauth, implement-sso, implement-scim.
> [Full setup guide](https://docs.scalekit.com/dev-kit/build-with-ai/)

---

# Create client

Create the SDK client and run core auth helpers
<div class="sdk-client-page">

Create a `ScalekitClient` with your environment URL, client ID, and client secret. All other clients hang off this instance.

Store credentials in environment variables. Never hard-code secrets. After you create the client, use [Sessions](/saaskit/sdks/python/sessions/) to work with sessions or open a domain client such as [Organizations](/saaskit/sdks/python/organization/) or [Users](/saaskit/sdks/python/user/).

### get_authorization_url
<div class="sdk-method-section">

      Method to get authorization URL

        Redirect URI for SAML SSO

        Auth URL options object

        Authorization URL

```python
import secrets
from scalekit import AuthorizationUrlOptions

# Security: generate a per-login OAuth state and store it in the session.
# Comparing the returned state on callback prevents login CSRF.
options = AuthorizationUrlOptions()
options.state = secrets.token_urlsafe(32)
options.organization_id = 'org_123456'
# request.session['oauth_state'] = options.state

auth_url = scalekit_client.get_authorization_url(
    'https://yourapp.com/auth/callback',
    options
)
# Redirect user to auth_url
```

</div>

### authenticate_with_code
<div class="sdk-method-section">

      Method to authenticate with code options

        authorization_code

        Redirect URI

        CodeAuthenticationOptions Object

        Tokens and claims.

```python
from scalekit import ScalekitClient

@app.get('/auth/callback')
async def auth_callback(request):
    code = request.query_params.get('code')
    state = request.query_params.get('state')

    # Security: reject the callback if state does not match the session value.
    if state != request.session.get('oauth_state'):
        return {'error': 'invalid state'}, 400

    result = scalekit_client.authenticate_with_code(
        code,
        'https://yourapp.com/auth/callback'
    )

    request.session['access_token'] = result['access_token']
    request.session['user'] = result['user']

    return RedirectResponse('/dashboard')
```

</div>

### get_idp_initiated_login_claims
<div class="sdk-method-section">

      Method to get IDP initiated login claims

        IDP initiated login token

        Optional request settings.

        Token audience.

        ```IdpInitiatedLoginClaims
        </CB.ClassMethodOutput>
        ```python wrap showLineNumbers=false
        @app.get('/auth/callback')
        async def auth_callback(request):
        idp_initiated_login = request.query_params.get('idp_initiated_login')

        if idp_initiated_login:
        claims = scalekit_client.get_idp_initiated_login_claims(idp_initiated_login)

        options = AuthorizationUrlOptions()
        options.connection_id = claims['connection_id']
        options.organization_id = claims['organization_id']
        options.login_hint = claims.get('login_hint')
        if claims.get('relay_state'):
            options.state = claims['relay_state']

        auth_url = scalekit_client.get_authorization_url(
            'https://yourapp.com/auth/callback',
            options
        )

        return RedirectResponse(auth_url)
        ```

</div>

### validate_access_token
<div class="sdk-method-section">

      Method to validate access token

        access token

        Optional validation settings. `issuer` accepts a string or a list; the token is valid if its `iss` claim equals any entry.

        Token audience.

        bool

```python
is_valid = scalekit_client.validate_access_token(token)
if is_valid:
    # Token is valid, proceed with request
    pass

# Accept more than one issuer, for example the environment URL and the server's own issuer
from scalekit.common.scalekit import TokenValidationOptions

options = TokenValidationOptions(
    issuer=[env_url, f"{env_url}/resources/{resource_id}"],
    audience=[expected_audience],
)
is_valid = scalekit_client.validate_access_token(token, options=options)
```

</div>

### get_logout_url
<div class="sdk-method-section">

      Method to get logout URL

        Logout URL options object

        str: The logout URL

```python
options = LogoutUrlOptions()
options.post_logout_redirect_uri = 'https://example.com'
options.state = 'some-state'

logout_url = scalekit_client.get_logout_url(options)
```

</div>

### verify_webhook_payload
<div class="sdk-method-section">

      Method to verify webhook payload

        Secret for webhook verification

        Webhook request headers

        Webhook payload in str or bytes

        bool

```python
import os

@app.post('/webhooks')
async def webhook_handler(request):
    payload = await request.body()
    headers = dict(request.headers)
    # Security: load the webhook secret from configuration — never hard-code it.
    # Skipping signature verification accepts forged webhook payloads as legitimate.
    secret = os.environ['SCALEKIT_WEBHOOK_SECRET']

    is_valid = scalekit_client.verify_webhook_payload(secret, headers, payload)

    if not is_valid:
        return {'error': 'invalid signature'}, 401

    # Process verified webhook
    return {'ok': True}
```

</div>

### refresh_access_token
<div class="sdk-method-section">

      Method to refresh access token using refresh token

        Refresh token to get new access token

        dict with access token & refresh token

```python
result = scalekit_client.refresh_access_token(refresh_token)
new_access_token = result['access_token']
new_refresh_token = result['refresh_token']
```

</div>

### generate_client_token
<div class="sdk-method-section">

      Method to generate access token

        Client Id for access token

        Client Secret for access token

        OAuth scopes.

        access token

</div>

### get_client_access_token
<div class="sdk-method-section">

      Method to generate an access token using the stored client credentials.

        access token string

</div>

### validate_access_token_and_get_claims
<div class="sdk-method-section">

      Method to validate access token and get claims

        access token

        Optional validation settings. `issuer` accepts a string or a list.

        Token audience.

        claims

</div>

### validate_token
<div class="sdk-method-section">

      Method to validate token

        token

        Optional validation settings. `issuer` accepts a string or a list.

        Optional. audience for validation

        payload

</div>

### verify_scopes
<div class="sdk-method-section">

      Verify that the token contains the required scopes

        The token to verify

        The scopes that must be present in the token

        bool: Returns True if all required scopes are present

</div>

### verify_interceptor_payload
<div class="sdk-method-section">

      Method to verify interceptor payload using common verification logic

        Secret for interceptor verification

        Headers.

        Interceptor payload in str or bytes

        bool

</div>

</div>


---

## More Scalekit documentation

| Resource | What it contains | When to use it |
|----------|-----------------|----------------|
| [/llms.txt](/llms.txt) | Structured index with routing hints per product area | Start here — find which documentation set covers your topic before loading full content |
| [/llms-full.txt](/llms-full.txt) | Complete documentation for all Scalekit products in one file | Use when you need exhaustive context across multiple products or when the topic spans several areas |
| [sitemap-0.xml](https://docs.scalekit.com/sitemap-0.xml) | Full URL list of every documentation page | Use to discover specific page URLs you can fetch for targeted, page-level answers |
