@venturekit/auth 0.0.0-dev.20260308002709 → 0.0.0-dev.20260311071358
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/README.md +81 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# @venturekit/auth
|
|
2
|
+
|
|
3
|
+
> **Warning:** This package is in active development and not production-ready. APIs may change without notice.
|
|
4
|
+
|
|
5
|
+
Authentication and authorization for [VentureKit](https://venturekit.dev) — Cognito integration, RBAC, scope checking, and JWT utilities.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @venturekit/auth@dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
`@venturekit/auth` provides:
|
|
16
|
+
|
|
17
|
+
- **Cognito configuration** — `createCognitoConfig()`, `buildUserPoolConfig()`
|
|
18
|
+
- **Role-based access control** — define roles, check scopes, validate permissions
|
|
19
|
+
- **Scope utilities** — `hasScope()`, `hasAnyScope()`, `hasAllScopes()`, `getScopesForRoles()`
|
|
20
|
+
- **Session/JWT utilities** — `decodeToken()`, `extractUserFromToken()`, `isTokenExpired()`
|
|
21
|
+
|
|
22
|
+
## Roles
|
|
23
|
+
|
|
24
|
+
Define roles that map to OAuth scopes:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import type { RolesConfig } from '@venturekit/auth';
|
|
28
|
+
|
|
29
|
+
const roles: RolesConfig = {
|
|
30
|
+
roles: [
|
|
31
|
+
{ name: 'viewer', description: 'Read only', scopes: ['users.read'] },
|
|
32
|
+
{ name: 'member', description: 'Standard user', scopes: ['users.read', 'users.write'] },
|
|
33
|
+
{ name: 'admin', description: 'Full access', scopes: ['users.read', 'users.write', 'admin.users'], isSystem: true },
|
|
34
|
+
],
|
|
35
|
+
defaultRole: 'viewer',
|
|
36
|
+
superAdminRole: 'admin',
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Scope Checking
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { hasScope, hasAnyScope, hasAllScopes, getScopesForRoles } from '@venturekit/auth';
|
|
44
|
+
|
|
45
|
+
const allScopes = getScopesForRoles(['member'], rolesConfig);
|
|
46
|
+
// → ['users.read', 'users.write']
|
|
47
|
+
|
|
48
|
+
hasScope(['member'], 'users.write', rolesConfig); // true
|
|
49
|
+
hasAnyScope(['viewer'], ['users.write'], rolesConfig); // false
|
|
50
|
+
hasAllScopes(['admin'], ['users.read', 'admin.users'], rolesConfig); // true
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## JWT Utilities
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { decodeToken, extractUserFromToken, isTokenExpired, getTokenExpiry } from '@venturekit/auth';
|
|
57
|
+
|
|
58
|
+
const claims = decodeToken(jwt); // Decode WITHOUT verification
|
|
59
|
+
const user = extractUserFromToken(jwt); // Extract user from ID token
|
|
60
|
+
const expired = isTokenExpired(jwt); // Check exp claim
|
|
61
|
+
const expiry = getTokenExpiry(jwt); // Get expiry as Date
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
> **Security:** `decodeToken` does NOT verify the JWT signature. Signature verification should be handled by API Gateway's Cognito Authorizer.
|
|
65
|
+
|
|
66
|
+
## Cognito Configuration
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { createCognitoConfig, buildUserPoolConfig } from '@venturekit/auth';
|
|
70
|
+
|
|
71
|
+
const cognitoConfig = createCognitoConfig(securityConfig);
|
|
72
|
+
const userPoolConfig = buildUserPoolConfig(cognitoConfig);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API Reference
|
|
76
|
+
|
|
77
|
+
See the [API reference](https://venturekit.dev/api-reference/auth) for full documentation.
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
Apache-2.0 — see [LICENSE](../../LICENSE) for details.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venturekit/auth",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.20260311071358",
|
|
4
4
|
"description": "Authentication and authorization for VentureKit",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@venturekit/core": "0.0.0-dev.
|
|
28
|
+
"@venturekit/core": "0.0.0-dev.20260311071358"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^20.10.0",
|