balena-auth 6.0.1 → 6.1.0
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 +19 -19
- package/build/api-key.d.ts +1 -1
- package/build/auth.d.ts +6 -1
- package/build/auth.js +8 -5
- package/build/auth.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -51,20 +51,20 @@ const auth = new BalenaAuth({
|
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
* [auth](#module_auth)
|
|
54
|
-
* [~setKey(key)](#module_auth..setKey) ⇒ <code>
|
|
55
|
-
* [~hasKey()](#module_auth..hasKey) ⇒ <code>
|
|
54
|
+
* [~setKey(key)](#module_auth..setKey) ⇒ <code>Promise.<void></code>
|
|
55
|
+
* [~hasKey()](#module_auth..hasKey) ⇒ <code>Promise.<Boolean></code>
|
|
56
56
|
* [~removeKey()](#module_auth..removeKey) ⇒ <code>Promise</code>
|
|
57
|
-
* [~getType()](#module_auth..getType) ⇒ <code>
|
|
58
|
-
* [~getKey()](#module_auth..getKey) ⇒ <code>
|
|
59
|
-
* [~getAge()](#module_auth..getAge) ⇒ <code>
|
|
60
|
-
* [~isExpired()](#module_auth..isExpired) ⇒ <code>
|
|
61
|
-
* [~isValid()](#module_auth..isValid) ⇒ <code>
|
|
62
|
-
* [~get2FAStatus()](#module_auth..get2FAStatus) ⇒ <code>
|
|
63
|
-
* [~needs2FA()](#module_auth..needs2FA) ⇒ <code>
|
|
57
|
+
* [~getType()](#module_auth..getType) ⇒ <code>Promise.<TokenType></code>
|
|
58
|
+
* [~getKey()](#module_auth..getKey) ⇒ <code>Promise.<string></code>
|
|
59
|
+
* [~getAge()](#module_auth..getAge) ⇒ <code>Promise.<(number\|undefined)></code>
|
|
60
|
+
* [~isExpired()](#module_auth..isExpired) ⇒ <code>Promise.<boolean></code>
|
|
61
|
+
* [~isValid()](#module_auth..isValid) ⇒ <code>Promise.<boolean></code>
|
|
62
|
+
* [~get2FAStatus()](#module_auth..get2FAStatus) ⇒ <code>Promise.<('not\_required'\|'pending'\|'passed')></code>
|
|
63
|
+
* [~needs2FA()](#module_auth..needs2FA) ⇒ <code>Promise.<boolean></code>
|
|
64
64
|
|
|
65
65
|
<a name="module_auth..setKey"></a>
|
|
66
66
|
|
|
67
|
-
### auth~setKey(key) ⇒ <code>
|
|
67
|
+
### auth~setKey(key) ⇒ <code>Promise.<void></code>
|
|
68
68
|
**Kind**: inner method of [<code>auth</code>](#module_auth)
|
|
69
69
|
**Summary**: Set the key
|
|
70
70
|
**Access**: public
|
|
@@ -79,10 +79,10 @@ auth.setKey('...').then(() => { ... });
|
|
|
79
79
|
```
|
|
80
80
|
<a name="module_auth..hasKey"></a>
|
|
81
81
|
|
|
82
|
-
### auth~hasKey() ⇒ <code>
|
|
82
|
+
### auth~hasKey() ⇒ <code>Promise.<Boolean></code>
|
|
83
83
|
**Kind**: inner method of [<code>auth</code>](#module_auth)
|
|
84
84
|
**Summary**: Has a key
|
|
85
|
-
**Returns**: <code>
|
|
85
|
+
**Returns**: <code>Promise.<Boolean></code> - has key
|
|
86
86
|
**Access**: public
|
|
87
87
|
**Example**
|
|
88
88
|
```js
|
|
@@ -102,7 +102,7 @@ auth.removeKey();
|
|
|
102
102
|
```
|
|
103
103
|
<a name="module_auth..getType"></a>
|
|
104
104
|
|
|
105
|
-
### auth~getType() ⇒ <code>
|
|
105
|
+
### auth~getType() ⇒ <code>Promise.<TokenType></code>
|
|
106
106
|
**Kind**: inner method of [<code>auth</code>](#module_auth)
|
|
107
107
|
**Summary**: Gets the key type
|
|
108
108
|
**Access**: public
|
|
@@ -112,7 +112,7 @@ auth.getType().then((type) => { ... });
|
|
|
112
112
|
```
|
|
113
113
|
<a name="module_auth..getKey"></a>
|
|
114
114
|
|
|
115
|
-
### auth~getKey() ⇒ <code>
|
|
115
|
+
### auth~getKey() ⇒ <code>Promise.<string></code>
|
|
116
116
|
**Kind**: inner method of [<code>auth</code>](#module_auth)
|
|
117
117
|
**Summary**: Gets the key
|
|
118
118
|
**Access**: public
|
|
@@ -122,7 +122,7 @@ auth.getKey().then((key) => { ... });
|
|
|
122
122
|
```
|
|
123
123
|
<a name="module_auth..getAge"></a>
|
|
124
124
|
|
|
125
|
-
### auth~getAge() ⇒ <code>
|
|
125
|
+
### auth~getAge() ⇒ <code>Promise.<(number\|undefined)></code>
|
|
126
126
|
**Kind**: inner method of [<code>auth</code>](#module_auth)
|
|
127
127
|
**Summary**: Gets the token age
|
|
128
128
|
**Access**: public
|
|
@@ -132,7 +132,7 @@ auth.getAge().then((age) => { ... });
|
|
|
132
132
|
```
|
|
133
133
|
<a name="module_auth..isExpired"></a>
|
|
134
134
|
|
|
135
|
-
### auth~isExpired() ⇒ <code>
|
|
135
|
+
### auth~isExpired() ⇒ <code>Promise.<boolean></code>
|
|
136
136
|
**Kind**: inner method of [<code>auth</code>](#module_auth)
|
|
137
137
|
**Summary**: Checks if token is expired
|
|
138
138
|
**Access**: public
|
|
@@ -142,7 +142,7 @@ auth.isExpired().then((expired) => { ... });
|
|
|
142
142
|
```
|
|
143
143
|
<a name="module_auth..isValid"></a>
|
|
144
144
|
|
|
145
|
-
### auth~isValid() ⇒ <code>
|
|
145
|
+
### auth~isValid() ⇒ <code>Promise.<boolean></code>
|
|
146
146
|
**Kind**: inner method of [<code>auth</code>](#module_auth)
|
|
147
147
|
**Summary**: Checks if token format is valid
|
|
148
148
|
**Access**: public
|
|
@@ -152,7 +152,7 @@ auth.isValid().then((valid) => { ... });
|
|
|
152
152
|
```
|
|
153
153
|
<a name="module_auth..get2FAStatus"></a>
|
|
154
154
|
|
|
155
|
-
### auth~get2FAStatus() ⇒ <code>
|
|
155
|
+
### auth~get2FAStatus() ⇒ <code>Promise.<('not\_required'\|'pending'\|'passed')></code>
|
|
156
156
|
**Kind**: inner method of [<code>auth</code>](#module_auth)
|
|
157
157
|
**Summary**: Gets whether passing a 2FA challenge is pending, passed or not required.
|
|
158
158
|
**Access**: public
|
|
@@ -162,7 +162,7 @@ auth.get2FAStatus().then((get2FAStatus) => { ... });
|
|
|
162
162
|
```
|
|
163
163
|
<a name="module_auth..needs2FA"></a>
|
|
164
164
|
|
|
165
|
-
### auth~needs2FA() ⇒ <code>
|
|
165
|
+
### auth~needs2FA() ⇒ <code>Promise.<boolean></code>
|
|
166
166
|
**Kind**: inner method of [<code>auth</code>](#module_auth)
|
|
167
167
|
**Summary**: Checks whether passing 2FA is pending/needed
|
|
168
168
|
**Access**: public
|
package/build/api-key.d.ts
CHANGED
package/build/auth.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module auth
|
|
3
|
+
*/
|
|
4
|
+
import { BalenaMalformedToken, BalenaExpiredToken } from 'balena-errors';
|
|
5
|
+
export { BalenaMalformedToken, BalenaExpiredToken };
|
|
1
6
|
import type { TokenType } from './token';
|
|
2
7
|
export { TokenType } from './token';
|
|
3
8
|
interface BalenaAuthOptions {
|
|
@@ -120,7 +125,7 @@ export default class BalenaAuth {
|
|
|
120
125
|
* @example
|
|
121
126
|
* auth.get2FAStatus().then((get2FAStatus) => { ... });
|
|
122
127
|
*/
|
|
123
|
-
get2FAStatus: () => Promise<
|
|
128
|
+
get2FAStatus: () => Promise<"not_required" | "pending" | "passed">;
|
|
124
129
|
/**
|
|
125
130
|
* @member needs2FA
|
|
126
131
|
* @summary Checks whether passing 2FA is pending/needed
|
package/build/auth.js
CHANGED
|
@@ -15,12 +15,15 @@ See the License for the specific language governing permissions and
|
|
|
15
15
|
limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.TokenType = void 0;
|
|
18
|
+
exports.TokenType = exports.BalenaExpiredToken = exports.BalenaMalformedToken = void 0;
|
|
19
19
|
const tslib_1 = require("tslib");
|
|
20
20
|
/**
|
|
21
21
|
* @module auth
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
// TODO-MAJOR: Remove balena-errors import altogether and create the relevant errors in this module instead.
|
|
24
|
+
const balena_errors_1 = require("balena-errors");
|
|
25
|
+
Object.defineProperty(exports, "BalenaMalformedToken", { enumerable: true, get: function () { return balena_errors_1.BalenaMalformedToken; } });
|
|
26
|
+
Object.defineProperty(exports, "BalenaExpiredToken", { enumerable: true, get: function () { return balena_errors_1.BalenaExpiredToken; } });
|
|
24
27
|
const balena_settings_storage_1 = require("balena-settings-storage");
|
|
25
28
|
const api_key_1 = require("./api-key");
|
|
26
29
|
const jwt_1 = require("./jwt");
|
|
@@ -186,10 +189,10 @@ class BalenaAuth {
|
|
|
186
189
|
this.createToken = (key) => {
|
|
187
190
|
const token = jwt_1.JWT.isValid(key) ? new jwt_1.JWT(key) : new api_key_1.APIKey(key);
|
|
188
191
|
if (!token.isValid()) {
|
|
189
|
-
throw new
|
|
192
|
+
throw new balena_errors_1.BalenaMalformedToken(key);
|
|
190
193
|
}
|
|
191
194
|
if (token.isExpired()) {
|
|
192
|
-
throw new
|
|
195
|
+
throw new balena_errors_1.BalenaExpiredToken(key);
|
|
193
196
|
}
|
|
194
197
|
return token;
|
|
195
198
|
};
|
|
@@ -199,7 +202,7 @@ class BalenaAuth {
|
|
|
199
202
|
}
|
|
200
203
|
const key = yield this.storage.get(this.tokenKey);
|
|
201
204
|
if (typeof key !== 'string') {
|
|
202
|
-
throw new
|
|
205
|
+
throw new balena_errors_1.BalenaMalformedToken(key);
|
|
203
206
|
}
|
|
204
207
|
this.token = this.createToken(key);
|
|
205
208
|
return this.token;
|
package/build/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;EAcE;;;;AAEF;;GAEG;AAEH,
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;EAcE;;;;AAEF;;GAEG;AAEH,4GAA4G;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AAI,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC;gBACvB,MAAM,IAAI,kCAAkB,CAAC,GAAG,CAAC,CAAC;YACnC,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC,CAAC;QAEM,aAAQ,GAAG,GAAyB,EAAE;YAC7C,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBAChB,OAAO,IAAI,CAAC,KAAK,CAAC;YACnB,CAAC;YAED,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAClD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;gBAC7B,MAAM,IAAI,oCAAoB,CAAC,GAAU,CAAC,CAAC;YAC5C,CAAC;YACD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,GAAa,CAAC,CAAC;YAC7C,OAAO,IAAI,CAAC,KAAK,CAAC;QACnB,CAAC,CAAA,CAAC;QApMD,IAAI,CAAC,OAAO,GAAG,IAAA,oCAAU,EAAC,EAAE,aAAa,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;CAmMD;AA3MD,6BA2MC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "balena-auth",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Balena session authentication utilities",
|
|
5
5
|
"main": "build/auth.js",
|
|
6
6
|
"types": "build/auth.d.ts",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@types/chai-as-promised": "^7.1.5",
|
|
48
48
|
"@types/jsonwebtoken": "^8.0.0",
|
|
49
49
|
"@types/mocha": "^9.1.1",
|
|
50
|
-
"@types/node": "^
|
|
50
|
+
"@types/node": "^16.18.126",
|
|
51
51
|
"balena-config-karma": "^4.0.0",
|
|
52
52
|
"balena-settings-client": "^4.0.0",
|
|
53
53
|
"buffer": "^5.7.1",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"chai-as-promised": "^7.1.1",
|
|
57
57
|
"crypto-browserify": "^3.12.0",
|
|
58
58
|
"husky": "^4.2.5",
|
|
59
|
-
"jsdoc-to-markdown": "^
|
|
59
|
+
"jsdoc-to-markdown": "^9.1.3",
|
|
60
60
|
"jsonwebtoken": "^8.0.0",
|
|
61
61
|
"karma": "^5.2.3",
|
|
62
62
|
"mocha": "^10.0.0",
|
|
@@ -80,6 +80,6 @@
|
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
"versionist": {
|
|
83
|
-
"publishedAt": "
|
|
83
|
+
"publishedAt": "2026-03-24T18:22:45.709Z"
|
|
84
84
|
}
|
|
85
85
|
}
|