@mastra/auth-cloud 1.2.5-alpha.0 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +20 -42
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,67 +1,45 @@
1
1
  # @mastra/auth-cloud
2
2
 
3
- Mastra Cloud authentication provider with PKCE OAuth flow.
3
+ `@mastra/auth-cloud` authenticates users through Mastra Cloud with a Proof Key for Code Exchange (PKCE) OAuth flow. Use it when a self-hosted Mastra server should delegate sign-in and session management to a Mastra Cloud project.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- pnpm add @mastra/auth-cloud
8
+ npm install @mastra/auth-cloud
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
+ Set `MASTRA_PROJECT_ID` before starting Mastra.
14
+
13
15
  ```typescript
16
+ import { MastraCloudAuthProvider } from '@mastra/auth-cloud';
14
17
  import { Mastra } from '@mastra/core/mastra';
15
- import { MastraCloudAuth } from '@mastra/auth-cloud';
16
-
17
- const auth = new MastraCloudAuth({
18
- projectId: process.env.MASTRA_PROJECT_ID!,
19
- // Optional: defaults to https://cloud.mastra.ai
20
- baseUrl: process.env.MASTRA_CLOUD_URL,
21
- // Optional: defaults to /auth/callback
22
- redirectPath: '/auth/callback',
23
- });
24
18
 
25
- const mastra = new Mastra({
19
+ export const mastra = new Mastra({
26
20
  server: {
27
- auth,
21
+ auth: new MastraCloudAuthProvider({
22
+ projectId: process.env.MASTRA_PROJECT_ID!,
23
+ cloudBaseUrl: 'https://cloud.mastra.ai',
24
+ callbackUrl: 'https://example.com/auth/callback',
25
+ isProduction: process.env.NODE_ENV === 'production',
26
+ }),
28
27
  },
29
28
  });
30
29
  ```
31
30
 
32
- ## Configuration
33
-
34
- | Option | Required | Default | Description |
35
- | -------------- | -------- | ------------------------- | ------------------------------- |
36
- | `projectId` | Yes | - | Project ID from cloud.mastra.ai |
37
- | `baseUrl` | No | `https://cloud.mastra.ai` | Mastra Cloud base URL |
38
- | `redirectPath` | No | `/auth/callback` | OAuth callback path |
39
- | `cookieName` | No | `mastra_session` | Session cookie name |
40
-
41
- ## Authentication Flow
42
-
43
- This package implements PKCE OAuth flow with Mastra Cloud:
44
-
45
- 1. User clicks login, redirected to Mastra Cloud with code challenge
46
- 2. User authenticates via Mastra Cloud (GitHub OAuth)
47
- 3. Mastra Cloud redirects back with authorization code
48
- 4. Package exchanges code + verifier for session token
49
- 5. Session token stored in HttpOnly cookie
31
+ ## Documentation
50
32
 
51
- ## API
33
+ `MastraCloudAuthProvider` implements Mastra's user, single sign-on, and session provider interfaces. It sends users through Mastra Cloud's PKCE authorization flow, validates the resulting session cookie, and accepts bearer tokens for API clients that do not use browser cookies.
52
34
 
53
- ### `MastraCloudAuth`
35
+ The constructor requires the Mastra Cloud `projectId`, the `cloudBaseUrl`, and the absolute OAuth `callbackUrl` registered for the application. Set `isProduction` to add the `Secure` attribute to authentication cookies. The provider also accepts the common Mastra auth options for public and protected routes and custom user authorization.
54
36
 
55
- The main authentication provider class implementing `MastraAuthProvider`.
37
+ During sign-in, the provider creates a PKCE verifier and challenge, redirects the browser to Mastra Cloud, exchanges the returned authorization code, and stores the session in an HTTP-only cookie. It exposes the login, callback, logout, session validation, and session refresh behavior required by Mastra's server authentication middleware.
56
38
 
57
- ### Methods
39
+ ## Changelog
58
40
 
59
- - `getLoginUrl(state?)` - Get OAuth login URL with PKCE
60
- - `handleCallback(code, verifier)` - Exchange code for session
61
- - `verifyToken(token)` - Verify session and get user with role
62
- - `refreshSession(token)` - Refresh expiring session
63
- - `logout(token)` - Invalidate session
41
+ See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/auth/cloud/CHANGELOG.md) for version history and release notes.
64
42
 
65
- ## License
43
+ ## Support
66
44
 
67
- Apache-2.0
45
+ We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/auth-cloud",
3
- "version": "1.2.5-alpha.0",
3
+ "version": "1.2.5",
4
4
  "description": "Mastra Cloud authentication with PKCE OAuth",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
- "@mastra/auth": "1.1.3-alpha.0"
23
+ "@mastra/auth": "1.1.3"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "hono": "^4.0.0"
@@ -33,9 +33,9 @@
33
33
  "tsdown": "0.22.9",
34
34
  "typescript": "^7.0.2",
35
35
  "vitest": "4.1.10",
36
- "@internal/auth": "0.0.19",
37
- "@internal/lint": "0.0.129",
38
- "@internal/types-builder": "0.0.104"
36
+ "@internal/lint": "0.0.130",
37
+ "@internal/types-builder": "0.0.105",
38
+ "@internal/auth": "0.0.20"
39
39
  },
40
40
  "files": [
41
41
  "dist"