@hitchy/plugin-auth 0.2.0 → 0.3.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.
Files changed (66) hide show
  1. package/.gitlab-ci.yml +42 -21
  2. package/LICENSE +21 -0
  3. package/api/controller/user.js +2 -29
  4. package/api/model/authorization/rule.js +0 -27
  5. package/api/model/role.js +0 -28
  6. package/api/model/user-to-role.js +0 -28
  7. package/api/model/user.js +2 -30
  8. package/api/policy/authentication.js +67 -64
  9. package/api/policy/authorization.js +0 -28
  10. package/api/policy/user.js +0 -28
  11. package/api/service/auth/manager.js +9 -28
  12. package/api/service/authentication/passport.js +1 -29
  13. package/api/service/authentication/strategies.js +176 -27
  14. package/api/service/authorization/node.js +0 -28
  15. package/api/service/authorization/policy-generator.js +0 -28
  16. package/api/service/authorization/tree.js +0 -28
  17. package/config/auth.js +5 -0
  18. package/coverage/base.css +224 -0
  19. package/coverage/block-navigation.js +79 -0
  20. package/coverage/favicon.png +0 -0
  21. package/coverage/index.html +231 -0
  22. package/coverage/plugin-auth/api/controller/index.html +111 -0
  23. package/coverage/plugin-auth/api/controller/user.js.html +368 -0
  24. package/coverage/plugin-auth/api/model/authorization/index.html +111 -0
  25. package/coverage/plugin-auth/api/model/authorization/rule.js.html +227 -0
  26. package/coverage/plugin-auth/api/model/index.html +141 -0
  27. package/coverage/plugin-auth/api/model/role.js.html +200 -0
  28. package/coverage/plugin-auth/api/model/user-to-role.js.html +167 -0
  29. package/coverage/plugin-auth/api/model/user.js.html +752 -0
  30. package/coverage/plugin-auth/api/policy/authentication.js.html +617 -0
  31. package/coverage/plugin-auth/api/policy/authorization.js.html +182 -0
  32. package/coverage/plugin-auth/api/policy/index.html +141 -0
  33. package/coverage/plugin-auth/api/policy/user.js.html +479 -0
  34. package/coverage/plugin-auth/api/service/auth/index.html +111 -0
  35. package/coverage/plugin-auth/api/service/auth/manager.js.html +863 -0
  36. package/coverage/plugin-auth/api/service/authentication/index.html +126 -0
  37. package/coverage/plugin-auth/api/service/authentication/passport.js.html +290 -0
  38. package/coverage/plugin-auth/api/service/authentication/strategies.js.html +860 -0
  39. package/coverage/plugin-auth/api/service/authorization/index.html +141 -0
  40. package/coverage/plugin-auth/api/service/authorization/node.js.html +944 -0
  41. package/coverage/plugin-auth/api/service/authorization/policy-generator.js.html +386 -0
  42. package/coverage/plugin-auth/api/service/authorization/tree.js.html +983 -0
  43. package/coverage/plugin-auth/config/auth.js.html +140 -0
  44. package/coverage/plugin-auth/config/index.html +111 -0
  45. package/coverage/plugin-auth/index.html +111 -0
  46. package/coverage/plugin-auth/index.js.html +344 -0
  47. package/coverage/prettify.css +1 -0
  48. package/coverage/prettify.js +2 -0
  49. package/coverage/sort-arrow-sprite.png +0 -0
  50. package/coverage/sorter.js +170 -0
  51. package/coverage/tmp/coverage-6744-1648396809135-0.json +1 -0
  52. package/docs/.vuepress/config.js +5 -2
  53. package/docs/api/config.md +14 -2
  54. package/docs/api/model/authorization-rule.md +1 -1
  55. package/docs/api/model/user.md +2 -2
  56. package/docs/api/service/authentication-passport.md +1 -1
  57. package/docs/guides/getting-started.md +2 -2
  58. package/docs/guides/idp-login.png +0 -0
  59. package/docs/guides/idp-saml-cert.png +0 -0
  60. package/docs/guides/openid-connect.md +164 -0
  61. package/docs/guides/readme.md +2 -0
  62. package/docs/guides/saml.md +161 -0
  63. package/docs/introduction.md +5 -5
  64. package/index.js +27 -50
  65. package/package.json +18 -13
  66. package/readme.md +11 -43
package/.gitlab-ci.yml CHANGED
@@ -7,40 +7,61 @@ cache:
7
7
  paths:
8
8
  - .npm
9
9
 
10
- .common-install: &common-install
11
- before_script:
12
- - npm ci --cache .npm --prefer-offline
13
10
 
14
- alpine-lts:
15
- <<: *common-install
11
+ .common-test: &common-test
16
12
  stage: test
17
- image: "node:lts-alpine"
18
13
  script:
14
+ - npm i -g npm
15
+ - node -v
16
+ - npm -v
17
+ - npm ci --cache .npm --prefer-offline
19
18
  - npm run lint
20
19
  - npm run test
21
20
 
21
+
22
+ alpine-current:
23
+ image: "node:current-alpine"
24
+ <<: *common-test
25
+
26
+ alpine-lts:
27
+ image: "node:lts-alpine"
28
+ <<: *common-test
29
+
30
+ alpine-old:
31
+ image: "node:erbium-alpine"
32
+ <<: *common-test
33
+ allow_failure: true
34
+
35
+ alpine-legacy:
36
+ image: "node:fermium-alpine"
37
+ <<: *common-test
38
+ allow_failure: true
39
+
40
+ debian-current:
41
+ image: "node:current"
42
+ <<: *common-test
43
+
22
44
  debian-lts:
23
- <<: *common-install
24
- stage: test
25
- image: "node:lts-buster"
26
- script:
27
- - npm run lint
28
- - npm run test
45
+ image: "node:lts"
46
+ <<: *common-test
47
+
48
+ debian-old:
49
+ image: "node:erbium"
50
+ <<: *common-test
51
+ allow_failure: true
52
+
53
+ debian-legacy:
54
+ image: "node:fermium"
55
+ <<: *common-test
56
+ allow_failure: true
29
57
 
30
- alpine-12:
31
- <<: *common-install
32
- stage: test
33
- image: "node:12-alpine"
34
- script:
35
- - npm run lint
36
- - npm run test
37
58
 
38
59
  pages:
39
- <<: *common-install
40
60
  stage: deploy
41
61
  image: node:lts-alpine
42
62
  script:
43
- - npm run doc:build
63
+ - npm ci --cache .npm --prefer-offline
64
+ - npm run docs:build
44
65
  artifacts:
45
66
  paths:
46
67
  - public
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 cepharum GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,31 +1,3 @@
1
- /**
2
- * (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
3
- *
4
- * The MIT License (MIT)
5
- *
6
- * Copyright (c) 2021 cepharum GmbH
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- * @author: cepharum
27
- */
28
-
29
1
  "use strict";
30
2
 
31
3
  module.exports = function() {
@@ -91,7 +63,8 @@ module.exports = function() {
91
63
  authenticated: req.user ? {
92
64
  uuid: req.user.uuid,
93
65
  name: req.user.name,
94
- roles: req.user.roles,
66
+ strategy: req.user.strategy || "local",
67
+ roles: req.user.roles.map( role => role.name ),
95
68
  } : false,
96
69
  } );
97
70
  },
@@ -1,30 +1,3 @@
1
- /**
2
- * (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
3
- *
4
- * The MIT License (MIT)
5
- *
6
- * Copyright (c) 2021 cepharum GmbH
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- * @author: cepharum
27
- */
28
1
  "use strict";
29
2
 
30
3
  module.exports = function() {
package/api/model/role.js CHANGED
@@ -1,31 +1,3 @@
1
- /**
2
- * (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
3
- *
4
- * The MIT License (MIT)
5
- *
6
- * Copyright (c) 2021 cepharum GmbH
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- * @author: cepharum
27
- */
28
-
29
1
  "use strict";
30
2
 
31
3
  /**
@@ -1,31 +1,3 @@
1
- /**
2
- * (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
3
- *
4
- * The MIT License (MIT)
5
- *
6
- * Copyright (c) 2021 cepharum GmbH
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- * @author: cepharum
27
- */
28
-
29
1
  "use strict";
30
2
 
31
3
  /**
package/api/model/user.js CHANGED
@@ -1,31 +1,3 @@
1
- /**
2
- * (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
3
- *
4
- * The MIT License (MIT)
5
- *
6
- * Copyright (c) 2021 cepharum GmbH
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- * @author: cepharum
27
- */
28
-
29
1
  "use strict";
30
2
 
31
3
  const crypto = require( "crypto" );
@@ -46,7 +18,7 @@ module.exports = function() {
46
18
  * @property {string} role name of user's role (user-role relationship is 1:n)
47
19
  * @property {string} password hash of user's password required for authenticating as
48
20
  * @property {string} strategy name of passport strategy used for authentication
49
- * @property {string} provider additional information specific to strategy used
21
+ * @property {string} strategyData additional information specific to strategy used
50
22
  *
51
23
  * @name Hitchy.Plugin.Auth.User
52
24
  */
@@ -58,7 +30,7 @@ module.exports = function() {
58
30
  },
59
31
  password: {},
60
32
  strategy: {},
61
- provider: {},
33
+ strategyData: {},
62
34
  },
63
35
  hooks: {
64
36
  afterValidate( errors ) {
@@ -1,31 +1,3 @@
1
- /**
2
- * (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
3
- *
4
- * The MIT License (MIT)
5
- *
6
- * Copyright (c) 2021 cepharum GmbH
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- * @author: cepharum
27
- */
28
-
29
1
  "use strict";
30
2
 
31
3
  module.exports = function() {
@@ -91,37 +63,50 @@ module.exports = function() {
91
63
  const { AuthenticationStrategies, AuthenticationPassport, AuthManager } = service;
92
64
  const defaultStrategy = AuthenticationStrategies.defaultStrategy();
93
65
 
94
- req.fetchBody().then( body => {
95
- req.body = body; // eslint-disable-line no-param-reassign
66
+ req.fetchBody()
67
+ .then( body => {
68
+ req.body = body; // eslint-disable-line no-param-reassign
96
69
 
97
- AuthenticationPassport.authenticate( strategy || defaultStrategy )( req, res, err => {
98
- if ( err ) {
99
- AlertLog( err );
100
- AuthenticationPolicy.logout( req, res, () => { next( err ); } );
101
- } else if ( req.user ) {
102
- const { uuid, name } = req.user;
70
+ return new Promise( ( resolve, reject ) => {
71
+ AuthenticationPassport.authenticate( strategy || defaultStrategy )( req, res, err => {
72
+ if ( err ) {
73
+ reject( err );
74
+ return;
75
+ }
103
76
 
104
- return AuthManager.listRolesOfUser( new model.User( uuid ) )
105
- .then( roles => {
106
- req.user.roles = roles; // eslint-disable-line no-param-reassign
77
+ if ( req.user ) {
78
+ const { uuid, name } = req.user;
107
79
 
108
- DebugLog( "authenticated as", req.user.name );
80
+ AuthManager.listRolesOfUser( new model.User( uuid ) )
81
+ .then( roles => {
82
+ req.user.roles = roles; // eslint-disable-line no-param-reassign
109
83
 
110
- res.set( "X-Authenticated-As", name );
111
- res.set( "X-Authorized-As", roles.join( "," ) );
84
+ DebugLog( "authenticated as", req.user.name );
112
85
 
113
- next();
114
- } );
115
- } else {
116
- AuthenticationPolicy.logout( req, res, next );
117
- }
86
+ res.set( "X-Authenticated-As", name );
87
+ res.set( "X-Authorized-As", roles.join( "," ) );
118
88
 
119
- return undefined;
89
+ resolve();
90
+ } )
91
+ .catch( reject );
92
+ } else {
93
+ AuthenticationPolicy.logout( req, res, cause => ( cause ? reject( cause ) : resolve() ) );
94
+ }
95
+ } );
96
+ } );
97
+ } )
98
+ .then( next )
99
+ .catch( err => {
100
+ AlertLog( err );
101
+
102
+ AuthenticationPolicy.logout( req, res, cause => {
103
+ if ( cause ) {
104
+ AlertLog( `applying logout policy after failed login has caused another issue: ${cause.stack}` );
105
+ }
106
+
107
+ next( err );
108
+ } );
120
109
  } );
121
- } ).catch( err => {
122
- AlertLog( err );
123
- AuthenticationPolicy.logout( req, res, () => next( err ) );
124
- } );
125
110
  }
126
111
 
127
112
  /**
@@ -133,21 +118,39 @@ module.exports = function() {
133
118
  * @returns {void}
134
119
  */
135
120
  static logout( req, res, next ) {
136
- try {
137
- if ( typeof req.logout === "function" ) {
138
- req.logout();
139
- }
121
+ Promise.resolve()
122
+ .then( () => {
123
+ // (optional) log out remotely using current user's authentication strategy
124
+ if ( req.user ) {
125
+ const strategyName = req.user.strategy;
126
+
127
+ if ( strategyName ) {
128
+ const strategy = api.config.auth.strategies[strategyName];
129
+
130
+ if ( strategy && typeof strategy.logOutRemotely === "function" ) {
131
+ return strategy.logOutRemotely( req );
132
+ }
133
+ }
134
+ }
135
+
136
+ return undefined;
137
+ } )
138
+ .then( async willLogoutInFuture => {
139
+ if ( !willLogoutInFuture ) {
140
+ if ( typeof req.logout === "function" ) {
141
+ await req.logout();
142
+ }
140
143
 
141
- req.session.drop();
142
- req.user = undefined; // eslint-disable-line no-param-reassign
144
+ req.session.drop();
145
+ req.user = undefined; // eslint-disable-line no-param-reassign
143
146
 
144
- res.set( "X-Authenticated-As", undefined );
145
- res.set( "X-Authorized-As", undefined );
147
+ res.set( "X-Authenticated-As", undefined );
148
+ res.set( "X-Authorized-As", undefined );
146
149
 
147
- next();
148
- } catch ( e ) {
149
- next( e );
150
- }
150
+ next();
151
+ }
152
+ } )
153
+ .catch( next );
151
154
  }
152
155
 
153
156
  /**
@@ -1,31 +1,3 @@
1
- /**
2
- * (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
3
- *
4
- * The MIT License (MIT)
5
- *
6
- * Copyright (c) 2021 cepharum GmbH
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- * @author: cepharum
27
- */
28
-
29
1
  "use strict";
30
2
 
31
3
  module.exports = function() {
@@ -1,31 +1,3 @@
1
- /**
2
- * (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
3
- *
4
- * The MIT License (MIT)
5
- *
6
- * Copyright (c) 2021 cepharum GmbH
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- * @author: cepharum
27
- */
28
-
29
1
  "use strict";
30
2
 
31
3
  module.exports = function() {
@@ -1,31 +1,3 @@
1
- /**
2
- * (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
3
- *
4
- * The MIT License (MIT)
5
- *
6
- * Copyright (c) 2021 cepharum GmbH
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- * @author: cepharum
27
- */
28
-
29
1
  "use strict";
30
2
 
31
3
  module.exports = function() {
@@ -89,6 +61,15 @@ module.exports = function() {
89
61
  }
90
62
 
91
63
  const { Role } = models;
64
+
65
+ if ( !( role instanceof Role ) ) {
66
+ role = String( role ); // eslint-disable-line no-param-reassign
67
+
68
+ if ( !/^[a-z_]/i.test( role ) || /\s/.test( role ) ) {
69
+ throw new TypeError( "missing role information" );
70
+ }
71
+ }
72
+
92
73
  const roles = role instanceof Role ? [role] : await Role.find( {
93
74
  eq: { name: "name", value: role.name || role },
94
75
  } );
@@ -1,31 +1,3 @@
1
- /**
2
- * (c) 2021 cepharum GmbH, Berlin, http://cepharum.de
3
- *
4
- * The MIT License (MIT)
5
- *
6
- * Copyright (c) 2021 cepharum GmbH
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- * @author: cepharum
27
- */
28
-
29
1
  "use strict";
30
2
 
31
3
  const PassportLib = require( "passport" );
@@ -86,7 +58,7 @@ module.exports = function() {
86
58
 
87
59
  if ( strategy ) {
88
60
  try {
89
- passport.use( strategy.name, strategy );
61
+ passport.use( name, strategy );
90
62
  } catch ( error ) {
91
63
  AlertLog( `using passport strategy ${name} failed:`, error );
92
64
  }