@hitchy/plugin-auth 0.4.4 → 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.
@@ -103,8 +103,8 @@ module.exports = function() {
103
103
  }
104
104
 
105
105
  /**
106
- * Generates local strategy authenticating user based on local user
107
- * model managed in local ODM.
106
+ * Generates local strategy authenticating user based on user model
107
+ * managed in local document-oriented database.
108
108
  *
109
109
  * @returns {Strategy} generated strategy for use with passport.js
110
110
  */
@@ -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.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",
@@ -23,7 +23,7 @@
23
23
  "homepage": "https://auth.hitchy.org",
24
24
  "peerDependencies": {
25
25
  "@hitchy/core": "0.8.x",
26
- "@hitchy/plugin-odem": "0.8.x",
26
+ "@hitchy/plugin-odem": "0.9.x",
27
27
  "@hitchy/plugin-cookies": "0.1.x",
28
28
  "@hitchy/plugin-session": "0.4.x"
29
29
  },
@@ -33,13 +33,13 @@
33
33
  "c8": "^10.1.2",
34
34
  "eslint": "^8.57.0",
35
35
  "eslint-config-cepharum": "^1.0.14",
36
- "eslint-plugin-promise": "^6.1.1",
37
- "mocha": "^10.6.0",
36
+ "eslint-plugin-promise": "^6.6.0",
37
+ "mocha": "^10.7.3",
38
38
  "openid-client": "^5.6.5",
39
39
  "passport-saml": "^3.2.4",
40
40
  "should": "^13.2.3",
41
41
  "should-http": "^0.1.1",
42
- "vitepress": "^1.3.1"
42
+ "vitepress": "^1.3.4"
43
43
  },
44
44
  "dependencies": {
45
45
  "passport": "^0.7.0",