🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@mastra/auth-cloud

Package Overview
Dependencies
Maintainers
6
Versions
193
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
This package has malicious versions linked to the ongoing "Mastra AI framework compromise" supply chain attack.

Affected versions:

1.1.4
View campaign page

@mastra/auth-cloud

Mastra Cloud authentication with PKCE OAuth

latest
Source
npmnpm
Version
1.2.0
Version published
Weekly downloads
2.3K
115.88%
Maintainers
6
Weekly downloads
 
Created
Source

@mastra/auth-cloud

Mastra Cloud authentication provider with PKCE OAuth flow.

Installation

pnpm add @mastra/auth-cloud

Usage

import { Mastra } from '@mastra/core/mastra';
import { MastraCloudAuth } from '@mastra/auth-cloud';

const auth = new MastraCloudAuth({
  projectId: process.env.MASTRA_PROJECT_ID!,
  // Optional: defaults to https://cloud.mastra.ai
  baseUrl: process.env.MASTRA_CLOUD_URL,
  // Optional: defaults to /auth/callback
  redirectPath: '/auth/callback',
});

const mastra = new Mastra({
  server: {
    auth,
  },
});

Configuration

OptionRequiredDefaultDescription
projectIdYes-Project ID from cloud.mastra.ai
baseUrlNohttps://cloud.mastra.aiMastra Cloud base URL
redirectPathNo/auth/callbackOAuth callback path
cookieNameNomastra_sessionSession cookie name

Authentication Flow

This package implements PKCE OAuth flow with Mastra Cloud:

  • User clicks login, redirected to Mastra Cloud with code challenge
  • User authenticates via Mastra Cloud (GitHub OAuth)
  • Mastra Cloud redirects back with authorization code
  • Package exchanges code + verifier for session token
  • Session token stored in HttpOnly cookie

API

MastraCloudAuth

The main authentication provider class implementing MastraAuthProvider.

Methods

  • getLoginUrl(state?) - Get OAuth login URL with PKCE
  • handleCallback(code, verifier) - Exchange code for session
  • verifyToken(token) - Verify session and get user with role
  • refreshSession(token) - Refresh expiring session
  • logout(token) - Invalidate session

License

Apache-2.0

FAQs

Package last updated on 19 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts