@robinpath/auth 0.1.0 → 0.1.1
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 +95 -0
- package/package.json +25 -7
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @robinpath/auth
|
|
2
|
+
|
|
3
|
+
> API authentication helpers: Basic, Bearer, API key, HMAC signing, and password hashing
|
|
4
|
+
|
|
5
|
+
   
|
|
6
|
+
|
|
7
|
+
## Why use this module?
|
|
8
|
+
|
|
9
|
+
The `auth` module lets you:
|
|
10
|
+
|
|
11
|
+
- Create a Basic authentication header from username and password
|
|
12
|
+
- Parse a Basic auth header to extract username and password
|
|
13
|
+
- Create a Bearer authentication header from a token
|
|
14
|
+
- Extract the token from a Bearer auth header
|
|
15
|
+
- Create an API key configuration for header or query parameter placement
|
|
16
|
+
|
|
17
|
+
All functions are callable directly from RobinPath scripts with a simple, consistent API.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @robinpath/auth
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
No credentials needed — start using it right away:
|
|
28
|
+
|
|
29
|
+
```robinpath
|
|
30
|
+
auth.parseBasic "Basic dXNlcjpwYXNz"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Available Functions
|
|
34
|
+
|
|
35
|
+
| Function | Description |
|
|
36
|
+
|----------|-------------|
|
|
37
|
+
| `auth.basic` | Create a Basic authentication header from username and password |
|
|
38
|
+
| `auth.parseBasic` | Parse a Basic auth header to extract username and password |
|
|
39
|
+
| `auth.bearer` | Create a Bearer authentication header from a token |
|
|
40
|
+
| `auth.parseBearer` | Extract the token from a Bearer auth header |
|
|
41
|
+
| `auth.apiKey` | Create an API key configuration for header or query parameter placement |
|
|
42
|
+
| `auth.hmacSign` | Create an HMAC signature for a payload |
|
|
43
|
+
| `auth.hmacVerify` | Verify an HMAC signature using timing-safe comparison |
|
|
44
|
+
| `auth.generateApiKey` | Generate a cryptographically secure random API key |
|
|
45
|
+
| `auth.hashPassword` | Hash a password using PBKDF2 with a random salt |
|
|
46
|
+
| `auth.verifyPassword` | Verify a password against a PBKDF2 hash (timing-safe) |
|
|
47
|
+
| `auth.buildAuthHeader` | Build an Authorization header from a type and credentials |
|
|
48
|
+
| `auth.parseAuthHeader` | Parse any Authorization header into its scheme and credentials |
|
|
49
|
+
|
|
50
|
+
## Examples
|
|
51
|
+
|
|
52
|
+
### Parse a Basic auth header to extract username and password
|
|
53
|
+
|
|
54
|
+
```robinpath
|
|
55
|
+
auth.parseBasic "Basic dXNlcjpwYXNz"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Create a Bearer authentication header from a token
|
|
59
|
+
|
|
60
|
+
```robinpath
|
|
61
|
+
auth.bearer "eyJhbGciOi..."
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Extract the token from a Bearer auth header
|
|
65
|
+
|
|
66
|
+
```robinpath
|
|
67
|
+
auth.parseBearer "Bearer eyJhbGciOi..."
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Integration with RobinPath
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { RobinPath } from "@wiredwp/robinpath";
|
|
74
|
+
import Module from "@robinpath/auth";
|
|
75
|
+
|
|
76
|
+
const rp = new RobinPath();
|
|
77
|
+
rp.registerModule(Module.name, Module.functions);
|
|
78
|
+
rp.registerModuleMeta(Module.name, Module.functionMetadata);
|
|
79
|
+
|
|
80
|
+
const result = await rp.executeScript(`
|
|
81
|
+
auth.parseBasic "Basic dXNlcjpwYXNz"
|
|
82
|
+
`);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Full API Reference
|
|
86
|
+
|
|
87
|
+
See [MODULE.md](./MODULE.md) for complete documentation including all parameters, return types, error handling, and advanced examples.
|
|
88
|
+
|
|
89
|
+
## Related Modules
|
|
90
|
+
|
|
91
|
+
- [`@robinpath/json`](../json) — JSON module for complementary functionality
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robinpath/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "API authentication helpers (Basic, Bearer, API key, HMAC) for RobinPath",
|
|
5
|
-
"publishConfig": {
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
6
8
|
"type": "module",
|
|
7
9
|
"main": "dist/index.js",
|
|
8
10
|
"types": "dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"test": "node --import tsx --test tests/*.test.ts"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@wiredwp/robinpath": ">=0.20.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@wiredwp/robinpath": "^0.30.1",
|
|
29
|
+
"tsx": "^4.19.0",
|
|
30
|
+
"typescript": "^5.6.0"
|
|
31
|
+
}
|
|
14
32
|
}
|