Skip to main content

Get Started

Set up Auth Kit to add user authentication and third-party service authorization to your SPECS Lenses.

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
  • SnapchatNot supported
  • SPECSFully supported
  • Camera Kit WebNot supported
  • Camera Kit MobileNot supported

Platform details

  • Snapchat — Not supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported.

  • Camera Kit Mobile — Not supported.

Prerequisites

  • Lens Studio 5.12.1 or later
  • An OAuth2 provider
  • SPECS App

Auth Kit uses OAuth2 authentication flow through the SPECS App, which requires a mobile device for testing. Deep link redirects are handled by the SPECS App and are not supported in the Lens Studio editor.

Auth Kit is exclusively designed for SPECS Lenses and uses the SPECS App for OAuth2 authentication. It is not supported for Snapchat Lenses.

About Auth Kit

Auth Kit enables secure user authentication with external services through the OAuth2 protocol, with all authentication flows handled by the SPECS App.

To start building authenticated experiences in your Lens using Auth Kit, follow the instructions below to start a new project in Lens Studio.

Package Resources

The Auth Kit package includes the following resources when imported into your Asset Browser:

  • OAuth2 Core: Main OAuth2 class and authentication logic optimized for SPECS
  • Token Management: Secure token and TokenManager classes with SPECS App integration
  • Deep Link Integration: Seamless OAuth2 redirect handling via SPECS App deep links

Required Redirect URI

Register a redirect URI that ends with your Lens Package ID. Package ID is fully under your control in Lens Studio, so the same URI works for development and for a published Lens—do not use the legacy …/oauth2redirect/unsecure path.

Set Package ID

On SPECS, your Lens is identified by the Package ID you set in Lens Studio—this is the lensId used by OAuth deep links. Set it before configuring your provider:

Project Settings → Platform Settings → SPECS → SPK Configuration → Package ID

Package ID in Project Settings

Choose a stable Package ID before shipping (for example, com.specs.example.authkit); changing it later breaks deep link routing and requires updating the redirect URI on every provider.

Standard OAuth2 Providers

https://lenses.specs.com/deeplink/specslink/oauth2redirect/[PACKAGE_ID]

Replace [PACKAGE_ID] with your Package ID, and pass the same URI as redirectUri when you construct OAuth2.

Google OAuth2

Google OAuth2 requires special setup and uses a different URI format with a custom scheme.

Setup Steps:

  1. Register your app as an "iOS application" in the Google Cloud Console
  2. Set Bundle ID to com.snap.spectacles when creating the iOS client
  3. Use the custom scheme format for redirect URIs as shown below

URI Format:

com.snap.spectacles:/specslink/oauth2redirect/[PACKAGE_ID]

Implementation Example:

const googleOAuth = new OAuth2({
clientId: 'YOUR_GOOGLE_CLIENT_ID',
authorizationUri: 'https://accounts.google.com/o/oauth2/v2/auth',
tokenUri: 'https://oauth2.googleapis.com/token',
redirectUri: 'com.snap.spectacles:/specslink/oauth2redirect/com.specs.example.authkit',
});

Starting a New project

Importing Auth Kit into a New Lens Studio Project

To start building an authenticated SPECS Lens from scratch using Auth Kit, follow these steps:

  1. Create a new Lens Studio project or open an existing SPECS project.

  2. Import the Auth Kit package from Asset Library. Follow this guide to learn how to install packages from the Asset Library.

  3. Create a new TypeScript script in your project and import the OAuth2 class from Auth Kit:

import { OAuth2 } from 'AuthKit.lspkg/Core/OAuth2';

  1. Configure your OAuth2 provider with the required settings for SPECS App integration:
const oauth = new OAuth2({
clientId: 'YOUR_CLIENT_ID', // Required: OAuth2 client ID
authorizationUri: 'https://example.com/oauth/authorize', // Required: Authorization endpoint
tokenUri: 'https://example.com/oauth/token', // Required: Token exchange endpoint
refreshUri: 'https://example.com/oauth/refresh', // Optional: Token refresh endpoint
clientSecret: 'YOUR_CLIENT_SECRET', // Optional: For confidential clients
// Must match Package ID under Project Settings → Platform Settings → SPECS → SPK Configuration
redirectUri:
'https://lenses.specs.com/deeplink/specslink/oauth2redirect/com.specs.example.authkit',
});

Basic Usage

The following examples are code snippets and may not be completed and won't run as-is.

Setting Up Auth Kit with OAuth2

import { OAuth2 } from 'OAuth2Kit.lspkg/Core/OAuth2';

// Create OAuth2 instance configured for SPECS App integration
const oauth = new OAuth2({
clientId: 'YOUR_CLIENT_ID', // Required: OAuth2 client ID
authorizationUri: 'https://example.com/oauth/authorize', // Required: Authorization endpoint
tokenUri: 'https://example.com/oauth/token', // Required: Token exchange endpoint
refreshUri: 'https://example.com/oauth/refresh', // Optional: Token refresh endpoint
clientSecret: 'YOUR_CLIENT_SECRET', // Optional: For confidential clients
// Must match Package ID under Project Settings → Platform Settings → SPECS → SPK Configuration
redirectUri:
'https://lenses.specs.com/deeplink/specslink/oauth2redirect/com.specs.example.authkit',
});

Starting Authentication via SPECS App

try {
// Start the OAuth2 authorization process through SPECS App
const token = await oauth.authorize('read write profile');

if (token) {
print('Successfully authorized via SPECS App!');

// Get access token for authenticated API calls
const accessToken = await oauth.getAccessToken();

// Make authenticated requests to your OAuth2 provider
const response = await fetch('https://api.provider.com/user', {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
}
} catch (error) {
print(`Authorization failed: ${error.message}`);
}

Checking Authorization Status

// Check if user is currently authorized through Auth Kit
if (oauth.isAuthorized) {
print('User is authenticated via SPECS App');
// Access token will be automatically refreshed if needed
const accessToken = await oauth.getAccessToken();
} else {
print('User needs to authenticate through SPECS App');
// Initiate OAuth2 authorization flow via SPECS App
await oauth.authorize('required scopes');
}

Sign Out

// Clear stored tokens and sign out user from Auth Kit
oauth.signOut();

Configuration Options

When creating an OAuth2 instance for Auth Kit, you can configure the following options:

OptionTypeRequiredDescription
clientIdstring✅Your OAuth2 client ID from the provider
authorizationUristring✅OAuth2 authorization endpoint URL
tokenUristring✅OAuth2 token exchange endpoint URL
refreshUristring?Token refresh endpoint (defaults to tokenUri)
clientSecretstring?OAuth2 client secret (for confidential clients)
authenticationTypestring✅Flow type: "code" (recommended for SPECS App)

Testing Requirements

Auth Kit is designed exclusively for SPECS and requires specific setup for testing:

Prerequisites for Testing

  1. SPECS device: Auth Kit is not compatible with Lens Studio Editor - you must test on a SPECS device
  2. SPECS App: Ensure the SPECS App is installed and ready on your mobile device
  3. Mobile Device: The SPECS App handles OAuth2 redirects and requires a connected mobile device
  4. Network Connection: Both SPECS and your mobile device need internet connectivity

Testing Steps

  1. Deploy your Lens to SPECS using Lens Studio
  2. Open the SPECS App on your mobile device
  3. Launch your Lens on SPECS
  4. Initiate authentication through your Lens interface
  5. Check your mobile device and a notification will appear to verify the OAuth2 connection
  6. Complete the authentication flow by following the prompts in the SPECS App

Error Handling

Auth Kit provides detailed error messages for common OAuth2 scenarios:

try {
await oauth.authorize('read write');
} catch (error) {
print(`Auth Kit OAuth2 error: ${error.message}`);
}