> **Building with AI coding agents?** Install the authstack plugin with one command. This equips your agent with accurate Scalekit implementation patterns.
>
> **Recommended**:
> ```bash
> npx @scalekit-inc/cli setup
> ```
>
> Global:
> ```bash
> npm install -g @scalekit-inc/cli
> scalekit setup
> ```
>
> Supports Claude Code, Cursor, GitHub Copilot, Codex + skills for 40+ agents.
> Features: full-stack-auth, agent-auth, mcp-auth, modular-sso, modular-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/node/sessions/) to validate tokens or open a domain client such as [Organizations](/saaskit/sdks/node/organizations/) or [Users](/saaskit/sdks/node/users/).

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

      Validates the access token and returns a boolean result.

      
        The token to be validated.
      
      
        Optional request settings.
      
      
        Returns true if the token is valid, false otherwise.
      

```typescript wrap showLineNumbers=false
const isValid = await scalekit.validateAccessToken(accessToken);
```

    
  
</div>

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

      Generates an M2M access token using the client credentials grant for the given clientId and clientSecret.

      
        The client ID to authenticate with
      
      
        The client secret to authenticate with
      
      
        The access token string
      

    
  
</div>

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

      Exchanges an authorization code for access tokens and user information.

      
        The authorization code received in the callback URL after.
      
      
        The same redirect URI used in getAuthorizationUrl().
      
      
        Optional request settings.
      
      
        Tokens and user claims.
      

```typescript wrap showLineNumbers=false
app.get('/auth/callback', async (req, res) => {
  const { code } = req.query;

  const result = await scalekit.authenticateWithCode(
    code,
    'https://yourapp.com/auth/callback'
  );

  req.session.accessToken = result.accessToken;
  req.session.user = result.user;

  res.redirect('/dashboard');
});
```

    
  
</div>

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

      Extracts and validates claims from an IdP-initiated login token.

      
        The token received in the 'idp_initiated_login' query.
      
      
        Optional request settings.
      
      
        The connection id.
      

```typescript wrap showLineNumbers=false
app.get('/auth/callback', async (req, res) => {
  const { idp_initiated_login } = req.query;

  if (idp_initiated_login) {
    const claims = await scalekit.getIdpInitiatedLoginClaims(idp_initiated_login);

    const authUrl = scalekit.getAuthorizationUrl(
      'https://yourapp.com/auth/callback',
      {
        connectionId: claims.connection_id,
        organizationId: claims.organization_id,
        loginHint: claims.login_hint,
        ...(claims.relay_state && { state: claims.relay_state })
      }
    );

    return res.redirect(authUrl);
  }
});
```

    
  
</div>

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

      Obtains a new access token using a refresh token.

      
        The refresh token obtained from a previous authentication
      
      
        Tokens and claims.
      

```typescript wrap showLineNumbers=false
const result = await scalekit.refreshAccessToken(oldRefreshToken);
// Store the new tokens
await storeTokens(userId, {
  accessToken: result.accessToken,
  refreshToken: result.refreshToken
});
```

    
  
</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 |
