@hitchy/plugin-auth 0.2.0 → 0.3.2

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 +127 -70
  9. package/api/policy/authorization.js +0 -28
  10. package/api/policy/user.js +0 -28
  11. package/api/service/auth/manager.js +45 -32
  12. package/api/service/authentication/passport.js +7 -34
  13. package/api/service/authentication/strategies.js +230 -58
  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 +8 -36
  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 +782 -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 +959 -0
  36. package/coverage/plugin-auth/api/service/authentication/index.html +126 -0
  37. package/coverage/plugin-auth/api/service/authentication/passport.js.html +293 -0
  38. package/coverage/plugin-auth/api/service/authentication/strategies.js.html +929 -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-8472-1648414315419-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 +31 -51
  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,39 +1,11 @@
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() {
32
4
  const api = this;
33
- const { services } = api.runtime;
5
+ const { models, services } = api.runtime;
34
6
 
35
- const AlertLog = api.log( "hitchy:plugin:auth:alert" );
36
- const DebugLog = api.log( "hitchy:plugin:auth:debug" );
7
+ const logAlert = api.log( "hitchy:plugin:auth:alert" );
8
+ const logDebug = api.log( "hitchy:plugin:auth:debug" );
37
9
 
38
10
  /**
39
11
  * Implements policy handlers transparently managing authentication process
@@ -76,6 +48,43 @@ module.exports = function() {
76
48
  } );
77
49
  }
78
50
 
51
+ /**
52
+ * Discovers HTTP basic authentication header and processes it
53
+ * accordingly based local user database.
54
+ *
55
+ * @param {Hitchy.Core.IncomingMessage} req request descriptor
56
+ * @param {Hitchy.Core.ServerResponse} res response manager
57
+ * @param {Hitchy.Core.ContinuationHandler} next invoke to continue request handling
58
+ * @returns {void}
59
+ */
60
+ static handleBasicAuth( req, res, next ) {
61
+ if ( req.user ) {
62
+ next();
63
+ return;
64
+ }
65
+
66
+ const match = /^basic\s+([a-z0-9+/]+={1,2})$/i.exec( req.headers.authorization );
67
+ if ( !match ) {
68
+ next();
69
+ return;
70
+ }
71
+
72
+ const decoded = Buffer.from( match[1], "base64" ).toString( "utf8" );
73
+ const parts = /^([^:]+):(.+)$/.exec( decoded );
74
+ if ( !parts ) {
75
+ next();
76
+ return;
77
+ }
78
+
79
+ services.AuthManager.checkAuthentication( parts[1], parts[2] )
80
+ .then( user => {
81
+ req.user = user; // eslint-disable-line no-param-reassign
82
+
83
+ this.qualifyAuthenticated( req, res, next );
84
+ } )
85
+ .catch( next );
86
+ }
87
+
79
88
  /**
80
89
  * Authenticates a request, updates server-side session accordingly and
81
90
  * injects information on authentication result in response header.
@@ -87,41 +96,71 @@ module.exports = function() {
87
96
  */
88
97
  static login( req, res, next ) {
89
98
  const { strategy } = req.params;
90
- const { model, service } = this;
91
- const { AuthenticationStrategies, AuthenticationPassport, AuthManager } = service;
99
+ const { AuthenticationStrategies, AuthenticationPassport } = services;
92
100
  const defaultStrategy = AuthenticationStrategies.defaultStrategy();
93
101
 
94
- req.fetchBody().then( body => {
95
- req.body = body; // eslint-disable-line no-param-reassign
102
+ req.fetchBody()
103
+ .then( body => {
104
+ req.body = body; // eslint-disable-line no-param-reassign
105
+
106
+ return new Promise( ( resolve, reject ) => {
107
+ AuthenticationPassport.authenticate( strategy || defaultStrategy )( req, res, err => {
108
+ if ( err ) {
109
+ reject( err );
110
+ } else {
111
+ this.qualifyAuthenticated( req, res, error => {
112
+ if ( error ) {
113
+ reject( error );
114
+ } else {
115
+ resolve();
116
+ }
117
+ } );
118
+ }
119
+ } );
120
+ } );
121
+ } )
122
+ .then( next )
123
+ .catch( err => {
124
+ logAlert( err );
125
+
126
+ AuthenticationPolicy.logout( req, res, cause => {
127
+ if ( cause ) {
128
+ logAlert( `applying logout policy after failed login has caused another issue: ${cause.stack}` );
129
+ }
96
130
 
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;
131
+ next( err );
132
+ } );
133
+ } );
134
+ }
103
135
 
104
- return AuthManager.listRolesOfUser( new model.User( uuid ) )
105
- .then( roles => {
106
- req.user.roles = roles; // eslint-disable-line no-param-reassign
136
+ /**
137
+ * Extends request descriptor in case some authenticated user has been
138
+ * found recently.
139
+ *
140
+ * @param {Hitchy.Core.IncomingMessage} req request descriptor
141
+ * @param {Hitchy.Core.ServerResponse} res response manager
142
+ * @param {Hitchy.Core.ContinuationHandler} next invoke to continue request handling
143
+ * @returns {void}
144
+ */
145
+ static qualifyAuthenticated( req, res, next ) {
146
+ if ( req.user ) {
147
+ const { uuid, name } = req.user;
107
148
 
108
- DebugLog( "authenticated as", req.user.name );
149
+ services.AuthManager.listRolesOfUser( new models.User( uuid ) )
150
+ .then( roles => {
151
+ req.user.roles = roles; // eslint-disable-line no-param-reassign
109
152
 
110
- res.set( "X-Authenticated-As", name );
111
- res.set( "X-Authorized-As", roles.join( "," ) );
153
+ logDebug( "authenticated as", req.user.name );
112
154
 
113
- next();
114
- } );
115
- } else {
116
- AuthenticationPolicy.logout( req, res, next );
117
- }
155
+ res.set( "X-Authenticated-As", name );
156
+ res.set( "X-Authorized-As", roles.join( "," ) );
118
157
 
119
- return undefined;
120
- } );
121
- } ).catch( err => {
122
- AlertLog( err );
123
- AuthenticationPolicy.logout( req, res, () => next( err ) );
124
- } );
158
+ next();
159
+ } )
160
+ .catch( next );
161
+ } else {
162
+ AuthenticationPolicy.logout( req, res, next );
163
+ }
125
164
  }
126
165
 
127
166
  /**
@@ -133,21 +172,39 @@ module.exports = function() {
133
172
  * @returns {void}
134
173
  */
135
174
  static logout( req, res, next ) {
136
- try {
137
- if ( typeof req.logout === "function" ) {
138
- req.logout();
139
- }
175
+ Promise.resolve()
176
+ .then( () => {
177
+ // (optional) log out remotely using current user's authentication strategy
178
+ if ( req.user ) {
179
+ const strategyName = req.user.strategy;
180
+
181
+ if ( strategyName ) {
182
+ const strategy = api.config.auth.strategies[strategyName];
183
+
184
+ if ( strategy && typeof strategy.logOutRemotely === "function" ) {
185
+ return strategy.logOutRemotely( req );
186
+ }
187
+ }
188
+ }
140
189
 
141
- req.session.drop();
142
- req.user = undefined; // eslint-disable-line no-param-reassign
190
+ return undefined;
191
+ } )
192
+ .then( async willLogoutInFuture => {
193
+ if ( !willLogoutInFuture ) {
194
+ if ( typeof req.logout === "function" ) {
195
+ await req.logout();
196
+ }
143
197
 
144
- res.set( "X-Authenticated-As", undefined );
145
- res.set( "X-Authorized-As", undefined );
198
+ req.session.drop();
199
+ req.user = undefined; // eslint-disable-line no-param-reassign
146
200
 
147
- next();
148
- } catch ( e ) {
149
- next( e );
150
- }
201
+ res.set( "X-Authenticated-As", undefined );
202
+ res.set( "X-Authorized-As", undefined );
203
+
204
+ next();
205
+ }
206
+ } )
207
+ .catch( next );
151
208
  }
152
209
 
153
210
  /**
@@ -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() {