@mastra/auth-auth0 0.0.0-declaration-maps-20250729231921 → 0.0.0-gl-test-20250917080133
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.
- package/CHANGELOG.md +43 -1
- package/README.md +0 -4
- package/dist/{chunk-B2N25K77.cjs → chunk-FID6GZ7C.cjs} +30 -30
- package/dist/chunk-FID6GZ7C.cjs.map +1 -0
- package/dist/{chunk-32EQK4OY.js → chunk-NFPWCYXA.js} +30 -30
- package/dist/chunk-NFPWCYXA.js.map +1 -0
- package/dist/{getMachineId-bsd-G4THBH3V.js → getMachineId-bsd-33IUL36D.js} +3 -3
- package/dist/{getMachineId-bsd-G4THBH3V.js.map → getMachineId-bsd-33IUL36D.js.map} +1 -1
- package/dist/{getMachineId-bsd-GQTQCD37.cjs → getMachineId-bsd-7LX32PWC.cjs} +5 -5
- package/dist/{getMachineId-bsd-GQTQCD37.cjs.map → getMachineId-bsd-7LX32PWC.cjs.map} +1 -1
- package/dist/{getMachineId-darwin-43NRSF2D.cjs → getMachineId-darwin-2GRB6VRE.cjs} +4 -4
- package/dist/{getMachineId-darwin-43NRSF2D.cjs.map → getMachineId-darwin-2GRB6VRE.cjs.map} +1 -1
- package/dist/{getMachineId-darwin-3P7FJFHV.js → getMachineId-darwin-Y4EF6EE5.js} +3 -3
- package/dist/{getMachineId-darwin-3P7FJFHV.js.map → getMachineId-darwin-Y4EF6EE5.js.map} +1 -1
- package/dist/{getMachineId-linux-TZ3NOAZ5.cjs → getMachineId-linux-6PTMU7AF.cjs} +4 -4
- package/dist/{getMachineId-linux-TZ3NOAZ5.cjs.map → getMachineId-linux-6PTMU7AF.cjs.map} +1 -1
- package/dist/{getMachineId-linux-H4F4I7A5.js → getMachineId-linux-ZMMZL7AP.js} +3 -3
- package/dist/{getMachineId-linux-H4F4I7A5.js.map → getMachineId-linux-ZMMZL7AP.js.map} +1 -1
- package/dist/{getMachineId-unsupported-T3AERO5R.js → getMachineId-unsupported-AM53N2Q3.js} +3 -3
- package/dist/{getMachineId-unsupported-T3AERO5R.js.map → getMachineId-unsupported-AM53N2Q3.js.map} +1 -1
- package/dist/{getMachineId-unsupported-EZLLFFYA.cjs → getMachineId-unsupported-VSEGAZUW.cjs} +4 -4
- package/dist/{getMachineId-unsupported-EZLLFFYA.cjs.map → getMachineId-unsupported-VSEGAZUW.cjs.map} +1 -1
- package/dist/{getMachineId-win-B5AEGZT7.cjs → getMachineId-win-GHQJSLHS.cjs} +4 -4
- package/dist/{getMachineId-win-B5AEGZT7.cjs.map → getMachineId-win-GHQJSLHS.cjs.map} +1 -1
- package/dist/{getMachineId-win-Z5QAASBF.js → getMachineId-win-RSU6GP4O.js} +3 -3
- package/dist/{getMachineId-win-Z5QAASBF.js.map → getMachineId-win-RSU6GP4O.js.map} +1 -1
- package/dist/index.cjs +89 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +81 -19
- package/dist/index.js.map +1 -1
- package/package.json +18 -4
- package/dist/chunk-32EQK4OY.js.map +0 -1
- package/dist/chunk-B2N25K77.cjs.map +0 -1
- package/eslint.config.js +0 -6
- package/src/index.test.ts +0 -112
- package/src/index.ts +0 -49
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
- package/tsup.config.ts +0 -25
- package/vitest.config.ts +0 -8
package/src/index.test.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { jwtVerify, createRemoteJWKSet } from 'jose';
|
|
2
|
-
import { beforeEach, afterEach, describe, expect, test, vi } from 'vitest';
|
|
3
|
-
import { MastraAuthAuth0 } from './index';
|
|
4
|
-
|
|
5
|
-
// Mock jose library
|
|
6
|
-
vi.mock('jose', () => ({
|
|
7
|
-
createRemoteJWKSet: vi.fn(),
|
|
8
|
-
jwtVerify: vi.fn(),
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
describe('MastraAuthAuth0', () => {
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
process.env.AUTH0_DOMAIN = 'test-domain.auth0.com';
|
|
14
|
-
process.env.AUTH0_AUDIENCE = 'test-audience';
|
|
15
|
-
vi.clearAllMocks();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
delete process.env.AUTH0_DOMAIN;
|
|
20
|
-
delete process.env.AUTH0_AUDIENCE;
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('constructor', () => {
|
|
24
|
-
test('initializes with environment variables', () => {
|
|
25
|
-
const auth0 = new MastraAuthAuth0();
|
|
26
|
-
expect(auth0['domain']).toBe('test-domain.auth0.com');
|
|
27
|
-
expect(auth0['audience']).toBe('test-audience');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('initializes with provided options', () => {
|
|
31
|
-
const auth0 = new MastraAuthAuth0({
|
|
32
|
-
domain: 'custom-domain.auth0.com',
|
|
33
|
-
audience: 'custom-audience',
|
|
34
|
-
});
|
|
35
|
-
expect(auth0['domain']).toBe('custom-domain.auth0.com');
|
|
36
|
-
expect(auth0['audience']).toBe('custom-audience');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('throws error when domain is missing', () => {
|
|
40
|
-
delete process.env.AUTH0_DOMAIN;
|
|
41
|
-
expect(() => new MastraAuthAuth0()).toThrow();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('throws error when audience is missing', () => {
|
|
45
|
-
delete process.env.AUTH0_AUDIENCE;
|
|
46
|
-
expect(() => new MastraAuthAuth0()).toThrow();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('authenticateToken', () => {
|
|
51
|
-
test('verifies JWT and returns payload', async () => {
|
|
52
|
-
const mockJWKS = vi.fn();
|
|
53
|
-
(createRemoteJWKSet as any).mockReturnValue(mockJWKS);
|
|
54
|
-
(jwtVerify as any).mockResolvedValue({
|
|
55
|
-
payload: { sub: 'user123', permissions: ['read'] },
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const auth0 = new MastraAuthAuth0();
|
|
59
|
-
const result = await auth0.authenticateToken('test-token');
|
|
60
|
-
|
|
61
|
-
expect(createRemoteJWKSet).toHaveBeenCalledWith(new URL('https://test-domain.auth0.com/.well-known/jwks.json'));
|
|
62
|
-
expect(jwtVerify).toHaveBeenCalledWith('test-token', mockJWKS, {
|
|
63
|
-
issuer: 'https://test-domain.auth0.com/',
|
|
64
|
-
audience: 'test-audience',
|
|
65
|
-
});
|
|
66
|
-
expect(result).toEqual({ sub: 'user123', permissions: ['read'] });
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('handles JWT verification failure', async () => {
|
|
70
|
-
(createRemoteJWKSet as any).mockReturnValue(vi.fn());
|
|
71
|
-
(jwtVerify as any).mockRejectedValue(new Error('Invalid token'));
|
|
72
|
-
|
|
73
|
-
const auth0 = new MastraAuthAuth0();
|
|
74
|
-
await expect(auth0.authenticateToken('invalid-token')).rejects.toThrow('Invalid token');
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe('authorizeUser', () => {
|
|
79
|
-
test('returns true for valid user', async () => {
|
|
80
|
-
const auth0 = new MastraAuthAuth0();
|
|
81
|
-
const result = await auth0.authorizeUser({ sub: 'user123' });
|
|
82
|
-
expect(result).toBe(true);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('returns false for null/undefined user', async () => {
|
|
86
|
-
const auth0 = new MastraAuthAuth0();
|
|
87
|
-
const result = await auth0.authorizeUser(null as any);
|
|
88
|
-
expect(result).toBe(false);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('can be overridden with custom authorization logic', async () => {
|
|
92
|
-
const auth0 = new MastraAuthAuth0({
|
|
93
|
-
async authorizeUser(user: any): Promise<boolean> {
|
|
94
|
-
// Custom authorization logic that checks for specific permissions
|
|
95
|
-
return user?.permissions?.includes('admin') ?? false;
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// Test with admin user
|
|
100
|
-
const adminUser = { sub: 'user123', permissions: ['admin'] };
|
|
101
|
-
expect(await auth0.authorizeUser(adminUser)).toBe(true);
|
|
102
|
-
|
|
103
|
-
// Test with non-admin user
|
|
104
|
-
const regularUser = { sub: 'user456', permissions: ['read'] };
|
|
105
|
-
expect(await auth0.authorizeUser(regularUser)).toBe(false);
|
|
106
|
-
|
|
107
|
-
// Test with user without permissions
|
|
108
|
-
const noPermissionsUser = { sub: 'user789' };
|
|
109
|
-
expect(await auth0.authorizeUser(noPermissionsUser)).toBe(false);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { MastraAuthProvider } from '@mastra/core/server';
|
|
2
|
-
import type { MastraAuthProviderOptions } from '@mastra/core/server';
|
|
3
|
-
|
|
4
|
-
import { createRemoteJWKSet, jwtVerify } from 'jose';
|
|
5
|
-
import type { JWTPayload } from 'jose';
|
|
6
|
-
|
|
7
|
-
type Auth0User = JWTPayload;
|
|
8
|
-
|
|
9
|
-
interface MastraAuthAuth0Options extends MastraAuthProviderOptions<Auth0User> {
|
|
10
|
-
domain?: string; // set this to your Auth0 domain
|
|
11
|
-
audience?: string; // set this to your Auth0 API identifier
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class MastraAuthAuth0 extends MastraAuthProvider<Auth0User> {
|
|
15
|
-
protected domain: string;
|
|
16
|
-
protected audience: string;
|
|
17
|
-
constructor(options?: MastraAuthAuth0Options) {
|
|
18
|
-
super({ name: options?.name ?? 'auth0' });
|
|
19
|
-
|
|
20
|
-
const domain = options?.domain ?? process.env.AUTH0_DOMAIN;
|
|
21
|
-
const audience = options?.audience ?? process.env.AUTH0_AUDIENCE;
|
|
22
|
-
|
|
23
|
-
if (!domain || !audience) {
|
|
24
|
-
throw new Error(
|
|
25
|
-
'Auth0 domain and audience are required, please provide them in the options or set the environment variables AUTH0_DOMAIN and AUTH0_AUDIENCE',
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
this.domain = domain;
|
|
30
|
-
this.audience = audience;
|
|
31
|
-
|
|
32
|
-
this.registerOptions(options);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async authenticateToken(token: string): Promise<Auth0User | null> {
|
|
36
|
-
const JWKS = createRemoteJWKSet(new URL(`https://${this.domain}/.well-known/jwks.json`));
|
|
37
|
-
|
|
38
|
-
const { payload } = await jwtVerify(token, JWKS, {
|
|
39
|
-
issuer: `https://${this.domain}/`,
|
|
40
|
-
audience: this.audience,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return payload;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async authorizeUser(user: Auth0User) {
|
|
47
|
-
return !!user;
|
|
48
|
-
}
|
|
49
|
-
}
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED
package/tsup.config.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
2
|
-
import { promisify } from 'util';
|
|
3
|
-
import { defineConfig } from 'tsup';
|
|
4
|
-
import type { Options } from 'tsup';
|
|
5
|
-
|
|
6
|
-
type Plugin = NonNullable<Options['plugins']>[number];
|
|
7
|
-
|
|
8
|
-
const exec = promisify(spawn);
|
|
9
|
-
|
|
10
|
-
export default defineConfig({
|
|
11
|
-
entry: ['src/index.ts'],
|
|
12
|
-
format: ['esm', 'cjs'],
|
|
13
|
-
clean: true,
|
|
14
|
-
dts: false,
|
|
15
|
-
splitting: true,
|
|
16
|
-
treeshake: {
|
|
17
|
-
preset: 'smallest',
|
|
18
|
-
},
|
|
19
|
-
sourcemap: true,
|
|
20
|
-
onSuccess: async () => {
|
|
21
|
-
await exec('pnpm', ['tsc', '-p', 'tsconfig.build.json'], {
|
|
22
|
-
stdio: 'inherit',
|
|
23
|
-
});
|
|
24
|
-
},
|
|
25
|
-
});
|