@hitchy/plugin-auth 0.4.5 → 0.4.6
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/api/service/authorization.js +21 -2
- package/package.json +2 -2
|
@@ -11,6 +11,27 @@ module.exports = function() {
|
|
|
11
11
|
* @alias Authorization
|
|
12
12
|
*/
|
|
13
13
|
class AuthorizationService {
|
|
14
|
+
/**
|
|
15
|
+
* Checks if described user is an administrator with privileged access.
|
|
16
|
+
*
|
|
17
|
+
* @param {User|string|undefined} user user to check, may be undefined if no user is known
|
|
18
|
+
* @returns {Promise<boolean>} promises result of check whether given user has privileged access or not
|
|
19
|
+
*/
|
|
20
|
+
static async isAdmin( user ) {
|
|
21
|
+
const userInfo = user ? await service.AuthManager.asUser( user ).catch( () => undefined ) : undefined;
|
|
22
|
+
const adminRole = service.AuthManager.adminRole;
|
|
23
|
+
|
|
24
|
+
if ( adminRole && Array.isArray( userInfo?.roles ) ) {
|
|
25
|
+
for ( const role of userInfo.roles ) {
|
|
26
|
+
if ( role?.name === adminRole ) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
14
35
|
/**
|
|
15
36
|
* Checks if given user may access named resource(s).
|
|
16
37
|
*
|
|
@@ -25,9 +46,7 @@ module.exports = function() {
|
|
|
25
46
|
}
|
|
26
47
|
|
|
27
48
|
const userInfo = user ? await service.AuthManager.asUser( user ).catch( () => undefined ) : undefined;
|
|
28
|
-
|
|
29
49
|
const resources = Array.isArray( resource ) ? resource : [resource];
|
|
30
|
-
|
|
31
50
|
const roleNames = Array.isArray( userInfo?.roles ) ? userInfo.roles.map( role => role.name ) : [];
|
|
32
51
|
|
|
33
52
|
if ( roleNames.indexOf( service.AuthManager.adminRole ) > -1 ) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitchy/plugin-auth",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "user authentication and authorization for Hitchy",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"passport-saml": "^3.2.4",
|
|
40
40
|
"should": "^13.2.3",
|
|
41
41
|
"should-http": "^0.1.1",
|
|
42
|
-
"vitepress": "^1.3.
|
|
42
|
+
"vitepress": "^1.3.4"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"passport": "^0.7.0",
|