Leo Auth SDK

4.0.5 · active · verified Wed Apr 22

The `leo-auth` SDK provides authentication utilities primarily for the LeoPlatform ecosystem, facilitating secure interactions with platform services. Currently stable at version 4.0.5, with ongoing development and recent pre-releases like `4.0.7-awsv3` indicating a continuous, albeit not rapid, release cadence. Key differentiators include its tight integration with AWS services, notably upgrading to AWS SDK v3 in the 4.x series, which offers modernized client configurations and improved performance. The SDK also incorporates security enhancements such as moving off TLSv1, and features like context overrides and `cognitoIdentityId` proxy for AWS key callers, indicating a focus on robust, cloud-native authentication flows. It is built to support Node.js environments and interacts with common authentication patterns for cloud applications.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `leo-auth` SDK and obtain guest credentials using environment variables for configuration. It outlines a basic setup suitable for Node.js applications interacting with the LeoPlatform's authentication mechanisms.

import { Auth } from 'leo-auth';

interface AuthConfig {
  clientId: string;
  identityPoolId: string;
  userPoolId: string;
  region: string;
}

// Load configuration from environment variables for security and flexibility
const authConfig: AuthConfig = {
  clientId: process.env.LEO_AUTH_CLIENT_ID ?? '',
  identityPoolId: process.env.LEO_AUTH_IDENTITY_POOL_ID ?? '',
  userPoolId: process.env.LEO_AUTH_USER_POOL_ID ?? '',
  region: process.env.AWS_REGION ?? 'us-east-1'
};

if (!authConfig.clientId || !authConfig.identityPoolId || !authConfig.userPoolId) {
  console.error('Missing LEO_AUTH_CLIENT_ID, LEO_AUTH_IDENTITY_POOL_ID, or LEO_AUTH_USER_POOL_ID environment variables.');
  process.exit(1);
}

async function initializeAndAuthenticate() {
  try {
    // Initialize the Auth SDK with your platform-specific configuration
    const auth = new Auth(authConfig);
    console.log('Leo Auth SDK initialized successfully.');

    // Example: Attempt a simple guest/unauthenticated authentication
    // Replace with actual login flow (e.g., cognito username/password, SAML) for real use cases
    const credentials = await auth.getGuestCredentials();
    console.log('Successfully obtained guest credentials.');
    console.log('Access Key ID:', credentials.accessKeyId);
    console.log('Secret Access Key:', credentials.secretAccessKey ? '******' : 'N/A');
    console.log('Session Token:', credentials.sessionToken ? '******' : 'N/A');

    // In a real application, you would now use these credentials
    // to make signed requests to other LeoPlatform or AWS services.

  } catch (error) {
    console.error('Authentication failed:', error);
    if (error instanceof Error) {
      console.error('Error message:', error.message);
    }
    process.exit(1);
  }
}

initializeAndAuthenticate();

view raw JSON →