@hitchy/plugin-auth 0.5.3 → 0.5.5
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.
|
@@ -4,6 +4,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
4
4
|
|
|
5
5
|
const logAlert = api.log( "hitchy:auth:alert" );
|
|
6
6
|
const logDebug = api.log( "hitchy:auth:debug" );
|
|
7
|
+
const logInfo = api.log( "hitchy:auth:info" );
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Implements policy handlers transparently managing authentication process
|
|
@@ -61,8 +62,9 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
const match = /^basic\s+([a-z0-9+/]+={
|
|
65
|
+
const match = /^basic\s+([a-z0-9+/]+={0,2})$/i.exec( req.headers.authorization );
|
|
65
66
|
if ( !match ) {
|
|
67
|
+
logDebug( "missing proper Authorization request header for basic authentication" );
|
|
66
68
|
next();
|
|
67
69
|
return;
|
|
68
70
|
}
|
|
@@ -70,6 +72,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
70
72
|
const decoded = Buffer.from( match[1], "base64" ).toString( "utf8" );
|
|
71
73
|
const parts = /^([^:]+):(.+)$/.exec( decoded );
|
|
72
74
|
if ( !parts ) {
|
|
75
|
+
logDebug( "decoding Authorization request header for basic authentication has failed" );
|
|
73
76
|
next();
|
|
74
77
|
return;
|
|
75
78
|
}
|
|
@@ -80,7 +83,11 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
80
83
|
|
|
81
84
|
this.qualifyAuthenticated( req, res, next );
|
|
82
85
|
} )
|
|
83
|
-
.catch(
|
|
86
|
+
.catch( cause => {
|
|
87
|
+
logInfo( `basic authentication failed: ${cause.message}` );
|
|
88
|
+
|
|
89
|
+
next( new service.HttpException( 403, "basic authentication failed" ) );
|
|
90
|
+
} );
|
|
84
91
|
}
|
|
85
92
|
|
|
86
93
|
/**
|
|
@@ -269,7 +269,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
269
269
|
|
|
270
270
|
switch ( candidates.length ) {
|
|
271
271
|
case 0 :
|
|
272
|
-
throw new services.HttpException(
|
|
272
|
+
throw new services.HttpException( 404, `no such local user: ${username}` );
|
|
273
273
|
|
|
274
274
|
case 1 : {
|
|
275
275
|
const [user] = candidates;
|
|
@@ -157,6 +157,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
157
157
|
*/
|
|
158
158
|
isAuthorized( selector, user, roles, acceptByDefault = false ) {
|
|
159
159
|
let result = 0;
|
|
160
|
+
let reason;
|
|
160
161
|
|
|
161
162
|
try {
|
|
162
163
|
this.selectNode( selector, false, node => {
|
|
@@ -164,6 +165,7 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
164
165
|
|
|
165
166
|
if ( localResult !== 0 ) {
|
|
166
167
|
result = localResult;
|
|
168
|
+
reason = ( localResult > 0 ? "granted" : "rejected" ) + " by " + node.path();
|
|
167
169
|
}
|
|
168
170
|
} );
|
|
169
171
|
} catch ( cause ) {
|
|
@@ -172,13 +174,16 @@ export default function() { // eslint-disable-line jsdoc/require-jsdoc
|
|
|
172
174
|
}
|
|
173
175
|
|
|
174
176
|
if ( result > 0 ) {
|
|
177
|
+
logDebug( `${user || "<guest>"} with roles ${roles ?? "<none>"} may access ${selector} (${reason})` );
|
|
175
178
|
return true;
|
|
176
179
|
}
|
|
177
180
|
|
|
178
181
|
if ( result < 0 ) {
|
|
182
|
+
logDebug( `${user || "<guest>"} with roles ${roles ?? "<none>"} must not access ${selector} (${reason})` );
|
|
179
183
|
return false;
|
|
180
184
|
}
|
|
181
185
|
|
|
186
|
+
logDebug( `${user || "<guest>"} with roles ${roles ?? "<none>"} ${acceptByDefault ? "may" : "must not"} access ${selector} by default` );
|
|
182
187
|
return Boolean( acceptByDefault );
|
|
183
188
|
}
|
|
184
189
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitchy/plugin-auth",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "user authentication and authorization for Hitchy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -28,17 +28,17 @@
|
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@hitchy/core": "1.x",
|
|
30
30
|
"@hitchy/plugin-cookies": "0.1.x",
|
|
31
|
-
"@hitchy/plugin-odem": "0.
|
|
31
|
+
"@hitchy/plugin-odem": "0.13.x",
|
|
32
32
|
"@hitchy/plugin-session": "0.4.x"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@hitchy/core": "^1.1.
|
|
35
|
+
"@hitchy/core": "^1.1.4",
|
|
36
36
|
"@hitchy/server-dev-tools": "^0.8.6",
|
|
37
37
|
"@hitchy/types": "^0.1.3",
|
|
38
38
|
"c8": "^10.1.3",
|
|
39
|
-
"eslint": "^9.
|
|
39
|
+
"eslint": "^9.23.0",
|
|
40
40
|
"eslint-config-cepharum": "^2.0.2",
|
|
41
|
-
"mermaid": "^11.
|
|
41
|
+
"mermaid": "^11.6.0",
|
|
42
42
|
"mocha": "^11.1.0",
|
|
43
43
|
"openid-client": "^5.7.1",
|
|
44
44
|
"passport-saml": "^3.2.4",
|