Skip to main content

Background

OAuth (Open Authorization) is an open-standard framework for access delegation, allowing applications to securely access a user’s protected resources without exposing their login credentials. By keeping passwords private and limiting access to sensitive information, OAuth improves both security and access management across web, mobile, and desktop applications. OAuth 2.0, the current and most widely adopted version, expands upon the original protocol to support APIs, mobile apps, and connected devices, offering multiple authorization flows tailored to different application types.
Corti Assistant requires user-based authentication. Client credentials flows and other machine-to-machine authentication methods are NOT supported for embedded Corti Assistant integrations. You must authenticate as an end user, not as an application.
When embedding Corti Assistant in your application (via iFrame/WebView), it’s important to use the right OAuth2 grant type that supports user-based authentication. This guide explains the OAuth flows that work with embedded Corti Assistant, focusing on user-based authentication methods that are suitable for interactive scenarios.

Supported OAuth Grant Types for Embedded Corti Assistant

The following OAuth flows support user-based authentication and can be used with embedded Corti Assistant. Client credentials grant is NOT supported as it does not provide user context. Best for: Native apps, single-page apps, or any browser-based integration where a user is present. Why: This flow is secure, interactive, and doesn’t require a client secret (ideal for public clients). Proof Key for Code Exchange (PKCE) protects against code interception attacks. How it works:
  1. Your app redirects the user to Corti’s OAuth2 authorization server.
  2. The user logs in and grants permission.
  3. Corti redirects back with an authorization code.
  4. Your app exchanges the code (with the PKCE verifier) for an access token.
Key Advantages:
  • Secure and suitable for embedded web apps.
  • No client secret is required.
  • Enforces user interaction.
This example uses the Corti JavaScript SDK (@corti/sdk)
Step 1: Generate Authorization URL (Frontend)
import { CortiAuth, CortiEnvironment } from "@corti/sdk";

const auth = new CortiAuth({
    environment: CortiEnvironment.Eu,
    tenantName: "YOUR_TENANT_NAME",
});

// SDK automatically generates code verifier, stores it in localStorage and makes redirect
await auth.authorizePkceUrl({
    clientId: "YOUR_CLIENT_ID",
    redirectUri: "https://your-app.com/callback"
});
Step 2: Handle the Callback and Exchange Code for Tokens
// Extract the authorization code from URL parameters
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
const error = urlParams.get('error');

if (error) {
    console.error('Authorization failed:', error);
    return;
}

if (code) {        
    // Exchange the authorization code for tokens using SDK
    const tokenResponse = await auth.getPkceFlowToken({
        clientId: "YOUR_CLIENT_ID",
        redirectUri: "https://your-app.com/callback",
        code: code,
    });

    const { accessToken, refreshToken } = tokenResponse;
}
Use this gold standard for Corti Assistant embedded use cases.

2. Authorization Code Flow (without PKCE)

Best for: Server-side web applications embedding Corti Assistant where the client secret can be safely stored on the backend. Why: Similar to PKCE, but requires storing a client secret — which is not safe in public or browser-based clients. Key Concerns:
  • Unsafe for apps where the frontend or iFrame can be inspected.
  • Only acceptable in secure backend environments where the client secret can be protected.
This example uses the Corti JavaScript SDK (@corti/sdk)
Step 1: Create Authorization URL
import { CortiAuth, CortiEnvironment } from "@corti/sdk";

const auth = new CortiAuth({
    environment: CortiEnvironment.Eu,
    tenantName: "YOUR_TENANT_NAME",
});

// Generate authorization URL
await auth.authorizeURL({
    clientId: "YOUR_CLIENT_ID",
    redirectUri: "https://your-app.com/callback",
});
Step 2: Handle the Callback and Exchange Code for Tokens
// Extract the authorization code from URL parameters
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
const error = urlParams.get('error');

if (error) {
    console.error('Authorization failed:', error);
    return;
}

if (code) {
    // Exchange the authorization code for tokens using SDK (client-side)
    const response = await fetch('http://localhost:3000/callback', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({ code }),
    });

    if (!response.ok) {
        throw new Error('Authentication failed');
    }
    
    const tokens = await response.json();
}
Step 3: Exchange Code for Access Token (Backend)
// server.js or routes/callback.js
import express from "express";
import { CortiAuth } from "@corti/sdk";

const app = express();

const CLIENT_ID     = "YOUR_CLIENT_ID";
const CLIENT_SECRET = "YOUR_CLIENT_SECRET";
const TENANT_NAME   = "YOUR_TENANT_NAME";
const ENVIRONMENT   = "YOUR_ENVIRONMENT";
const REDIRECT_URI  = "https://yourapp.com/callback"; // must match OAuth settings

app.get("/callback", async (req, res) => {
    const authCode = req.query.code;

    if (!authCode) {
        return res.status(400).send("Missing authorization code");
    }

    try {
        // Initialize CortiAuth SDK client
        const auth = new CortiAuth({
            environment: ENVIRONMENT,
            tenantName: TENANT_NAME,
        });

        // Exchange code for token
        const tokens = await auth.getCodeFlowToken({
            clientId: CLIENT_ID,
            clientSecret: CLIENT_SECRET,
            redirectUri: REDIRECT_URI,
            code: authCode,
        });

        // Example "do something": simply log the access token
        console.log("Access Token:", tokens.accessToken);

        // Redirect back to app with token in query param (example)
        res.json(tokens);
    } catch (err) {
        console.error("OAuth error:", err);
        return res.status(500).send("Failed to exchange authorization code");
    }
});

app.listen(3000, () => {
    console.log("Server running at http://localhost:3000");
});
Summary of the flow:
StepComponentDescription
1FrontendRedirects user to Corti login
2CortiRedirects back to your app with code
3BackendExchanges code + client secret for tokens
Responds with session/token, redirects to frontend
Requirements:
  • Must use HTTPS for redirect_uri
  • Your client_secret must not be exposed to the frontend
  • The code returned is valid for one use and short-lived
Use only if the OAuth2 flow is entirely server-to-server.

3. Resource Owner Password Credentials (ROPC) Grant (Use with caution)

Best for: Controlled environments embedding Corti Assistant with trusted clients (e.g., internal tools). Why: Allows username/password login directly in the app — but bypasses the authorization server UI. Risks:
  • Trains users to enter passwords into third-party apps.
  • Easy to misuse, violates best practices.
  • Only viable where UI constraints prevent redirecting (e.g., native kiosk apps without browsers).
This example uses the Corti JavaScript SDK (@corti/sdk)
import { CortiAuth, CortiClient, CortiEnvironment } from "@corti/sdk";

const CLIENT_ID = "YOUR_CLIENT_ID";
const USERNAME = "[email protected]";
const PASSWORD = "your-password";

// Step 1: Exchange credentials for tokens using ROPC flow
const auth = new CortiAuth({
    environment: CortiEnvironment.Eu,
    tenantName: "YOUR_TENANT_NAME",
});

const tokenResponse = await auth.getRopcFlowToken({
    clientId: CLIENT_ID,
    username: USERNAME,
    password: PASSWORD,
});

const { accessToken, refreshToken } = tokenResponse;
This authentication method is not recommended, but sometimes necessary.

Final Guidance

Important: Embedded Corti Assistant requires user-based authentication. Client credentials grant is NOT supported as it does not provide user context.
Pick the flow that matches your interaction model as offered above. See further details and contact us for support here. What to Use When:
  • For embedded Corti Assistant (e.g., in an iFrame/WebView):
    Use Authorization Code Flow with PKCE to authenticate the end user securely. This is the recommended flow for most embedded integrations.
  • For server-side integrations where you can securely store a client secret:
    Authorization Code Flow (without PKCE) may be used, but ensure the client secret is never exposed to the frontend.
  • For constrained environments without redirect capabilities:
    ROPC may be used with caution, but only in trusted internal environments.
  • Client Credentials is NOT supported — it does not provide user context and will not work with embedded Corti Assistant.
Additional Reference: