@travetto/auth 3.0.0-rc.2 → 3.0.0-rc.21
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 +18 -8
- package/package.json +8 -6
- package/src/types/authenticator.ts +6 -0
- package/src/types/principal.ts +1 -1
- package/src/util.ts +2 -2
- /package/{index.ts → __index__.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
<!-- This file was generated by @travetto/doc and should not be modified directly -->
|
|
2
|
-
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/auth/
|
|
2
|
+
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/auth/DOC.ts and execute "npx trv doc" to rebuild -->
|
|
3
3
|
# Authentication
|
|
4
|
-
## Authentication scaffolding for the
|
|
4
|
+
## Authentication scaffolding for the Travetto framework
|
|
5
5
|
|
|
6
6
|
**Install: @travetto/auth**
|
|
7
7
|
```bash
|
|
8
8
|
npm install @travetto/auth
|
|
9
|
+
|
|
10
|
+
# or
|
|
11
|
+
|
|
12
|
+
yarn add @travetto/auth
|
|
9
13
|
```
|
|
10
14
|
|
|
11
15
|
This module provides the high-level backdrop for managing security principals. The goal of this module is to be a centralized location for various security frameworks to plug into. The primary contributions are:
|
|
@@ -62,6 +66,12 @@ As referenced above, a [Principal Structure](https://github.com/travetto/travett
|
|
|
62
66
|
**Code: Authenticator**
|
|
63
67
|
```typescript
|
|
64
68
|
export interface Authenticator<T = unknown, P extends Principal = Principal, C = unknown> {
|
|
69
|
+
/**
|
|
70
|
+
* Allows for the authenticator to be initialized if needed
|
|
71
|
+
* @param ctx
|
|
72
|
+
*/
|
|
73
|
+
initialize?(ctx: C): Promise<void>;
|
|
74
|
+
|
|
65
75
|
/**
|
|
66
76
|
* Verify the payload, ensuring the payload is correctly identified.
|
|
67
77
|
*
|
|
@@ -110,8 +120,8 @@ The [AuthUtil](https://github.com/travetto/travetto/tree/main/module/auth/src/ut
|
|
|
110
120
|
|
|
111
121
|
**Code: Auth util structure**
|
|
112
122
|
```typescript
|
|
113
|
-
import
|
|
114
|
-
import
|
|
123
|
+
import crypto from 'crypto';
|
|
124
|
+
import util from 'util';
|
|
115
125
|
import { AppError, Util } from '@travetto/base';
|
|
116
126
|
const pbkdf2 = util.promisify(crypto.pbkdf2);
|
|
117
127
|
/**
|
|
@@ -123,7 +133,7 @@ export class AuthUtil {
|
|
|
123
133
|
*
|
|
124
134
|
* @param roles Roles to build matcher for
|
|
125
135
|
*/
|
|
126
|
-
static roleMatcher(roles: string[]): (perms: Set<string>) => boolean
|
|
136
|
+
static roleMatcher(roles: string[]): (perms: Set<string>) => boolean;
|
|
127
137
|
/**
|
|
128
138
|
* Generate a hash for a given value
|
|
129
139
|
*
|
|
@@ -133,7 +143,7 @@ export class AuthUtil {
|
|
|
133
143
|
* @param keylen Length of hash
|
|
134
144
|
* @param digest Digest method
|
|
135
145
|
*/
|
|
136
|
-
static generateHash(value: string, salt: string, iterations = 25000, keylen = 256, digest = 'sha256'): Promise<string
|
|
146
|
+
static generateHash(value: string, salt: string, iterations = 25000, keylen = 256, digest = 'sha256'): Promise<string>;
|
|
137
147
|
/**
|
|
138
148
|
* Generate a salted password, with the ability to validate the password
|
|
139
149
|
*
|
|
@@ -141,11 +151,11 @@ export class AuthUtil {
|
|
|
141
151
|
* @param salt Salt value, or if a number, length of salt
|
|
142
152
|
* @param validator Optional function to validate your password
|
|
143
153
|
*/
|
|
144
|
-
static async generatePassword(password: string, salt: number | string = 32): Promise<{ salt: string, hash: string }
|
|
154
|
+
static async generatePassword(password: string, salt: number | string = 32): Promise<{ salt: string, hash: string }>;
|
|
145
155
|
}
|
|
146
156
|
```
|
|
147
157
|
|
|
148
|
-
`roleMatcher` is probably the only functionality that needs to be explained. The function extends the core allow/deny matcher functionality from [Base](https://github.com/travetto/travetto/tree/main/module/base#readme "
|
|
158
|
+
`roleMatcher` is probably the only functionality that needs to be explained. The function extends the core allow/deny matcher functionality from [Base](https://github.com/travetto/travetto/tree/main/module/base#readme "Environment config and common utilities for travetto applications.")'s Util class.
|
|
149
159
|
|
|
150
160
|
An example of role checks could be:
|
|
151
161
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/auth",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "Authentication scaffolding for the travetto framework",
|
|
3
|
+
"version": "3.0.0-rc.21",
|
|
4
|
+
"description": "Authentication scaffolding for the Travetto framework",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"authentication",
|
|
8
7
|
"travetto",
|
|
@@ -15,16 +14,19 @@
|
|
|
15
14
|
"name": "Travetto Framework"
|
|
16
15
|
},
|
|
17
16
|
"files": [
|
|
18
|
-
"
|
|
17
|
+
"__index__.ts",
|
|
19
18
|
"src"
|
|
20
19
|
],
|
|
21
|
-
"main": "
|
|
20
|
+
"main": "__index__.ts",
|
|
22
21
|
"repository": {
|
|
23
22
|
"url": "https://github.com/travetto/travetto.git",
|
|
24
23
|
"directory": "module/auth"
|
|
25
24
|
},
|
|
26
25
|
"dependencies": {
|
|
27
|
-
"@travetto/base": "^3.0.0-rc.
|
|
26
|
+
"@travetto/base": "^3.0.0-rc.21"
|
|
27
|
+
},
|
|
28
|
+
"travetto": {
|
|
29
|
+
"displayName": "Authentication"
|
|
28
30
|
},
|
|
29
31
|
"private": false,
|
|
30
32
|
"publishConfig": {
|
|
@@ -6,6 +6,12 @@ import { Principal } from './principal';
|
|
|
6
6
|
* @concrete ../internal/types:AuthenticatorTarget
|
|
7
7
|
*/
|
|
8
8
|
export interface Authenticator<T = unknown, P extends Principal = Principal, C = unknown> {
|
|
9
|
+
/**
|
|
10
|
+
* Allows for the authenticator to be initialized if needed
|
|
11
|
+
* @param ctx
|
|
12
|
+
*/
|
|
13
|
+
initialize?(ctx: C): Promise<void>;
|
|
14
|
+
|
|
9
15
|
/**
|
|
10
16
|
* Verify the payload, ensuring the payload is correctly identified.
|
|
11
17
|
*
|
package/src/types/principal.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* A user principal, including permissions and details
|
|
3
3
|
*
|
|
4
4
|
* @concrete ../internal/types:PrincipalTarget
|
|
5
|
-
* @augments `@
|
|
5
|
+
* @augments `@travetto/rest:Context`
|
|
6
6
|
*/
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
8
|
export interface Principal<D = { [key: string]: any }> {
|
package/src/util.ts
CHANGED
|
File without changes
|