Skip to main content
This guide covers authentication methods for integrating AGO APIs in your mobile application.

Base URL

Authentication Modes

AGO supports two authentication modes for mobile integration: JWT Authentication for users with accounts, and Widget Authentication for anonymous users or embedded chat widgets.

1. JWT Authentication (Authenticated Mode)

For users with accounts, use JWT tokens alongside the widget authentication headers. The Authorization header is added to the standard widget headers:
When a JWT is sent, the X-User-Anon-Id header is optional: the user identity is taken from the token’s sub claim.

When to Use JWT

  • Users have registered accounts in your system
  • You want full user identity and history
  • Users log in through your existing authentication flow

Obtaining a JWT Token

Your backend should generate JWT tokens after user authentication. The token must be signed with the secret configured in your AGO instance.

2. Widget Authentication (Anonymous Mode)

For anonymous users or embedded chat widgets, use widget authentication with the following headers:

Header Reference

How Widget Mode Works:
  1. The system creates an anonymous user with email format: unknown_ago@{user-id}.com
  2. All conversations are tied to this anonymous user
  3. The same user ID should be used across sessions for conversation continuity
  4. The real email (if provided) is stored in additional_info for admin reference

Widget Mode Setup

Prerequisites

Before using widget mode in your mobile app:
  1. Allow Your Domain: Add your app’s domain/origin to the allowed domains list
  2. Persistent Storage: Store the user ID persistently to maintain conversation continuity

Security Considerations

  • User ID: Must be unique per device/user and stored persistently
  • Domain Validation: The Origin header must match allowed domains exactly
  • Anonymous Users: System creates users with format unknown_ago@{user-id}.com
  • Real Email Tracking: Optional X-Widget-Email is stored separately for admin reference

Implementation Examples

Swift (iOS) - JWT Mode

Swift (iOS) - Widget Mode

Kotlin (Android) - JWT Mode

Kotlin (Android) - Widget Mode


Best Practices

Authentication Mode Selection

  • Use JWT mode for registered users with accounts
  • Use Widget mode for anonymous users or embedded chat scenarios
  • Never mix authentication modes in the same session

User ID Management

  • Generate UUID once per installation
  • Store persistently (UserDefaults/SharedPreferences)
  • Use same ID across app sessions for conversation continuity
  • Clear ID only on app uninstall or user logout

Error Handling

  • Handle 401 errors (invalid or expired token)
  • Handle 403 errors (domain not in allowed list)
  • Implement token refresh for JWT mode
  • Show user-friendly error messages