@@ -2,18 +2,15 @@ const SamlStrategy = require('@node-saml/passport-saml').Strategy
2
2
, log = require ( 'winston' )
3
3
, User = require ( '../models/user' )
4
4
, Role = require ( '../models/role' )
5
- , Device = require ( '../models/device' )
6
5
, TokenAssertion = require ( './verification' ) . TokenAssertion
7
6
, api = require ( '../api' )
8
- , userTransformer = require ( '../transformers/user' )
9
- , AuthenticationInitializer = require ( './index' )
10
- , authenticationApiAppender = require ( '../utilities/authenticationApiAppender' ) ;
7
+ , AuthenticationInitializer = require ( './index' ) ;
11
8
12
9
function configure ( strategy ) {
13
10
log . info ( 'Configuring ' + strategy . title + ' authentication' ) ;
14
11
15
12
const options = {
16
- path : `/auth/${ strategy . name } /callback` ,
13
+ callbackUrl : `${ strategy . redirectHost } /auth/${ strategy . name } /callback` ,
17
14
entryPoint : strategy . settings . entryPoint ,
18
15
cert : strategy . settings . cert ,
19
16
issuer : strategy . settings . issuer
@@ -27,49 +24,49 @@ function configure(strategy) {
27
24
if ( strategy . settings . signatureAlgorithm ) {
28
25
options . signatureAlgorithm = strategy . settings . signatureAlgorithm ;
29
26
}
30
- if ( strategy . settings . audience ) {
27
+ if ( strategy . settings . audience ) {
31
28
options . audience = strategy . settings . audience ;
32
29
}
33
- if ( strategy . settings . identifierFormat ) {
30
+ if ( strategy . settings . identifierFormat ) {
34
31
options . identifierFormat = strategy . settings . identifierFormat ;
35
32
}
36
- if ( strategy . settings . acceptedClockSkewMs ) {
33
+ if ( strategy . settings . acceptedClockSkewMs ) {
37
34
options . acceptedClockSkewMs = strategy . settings . acceptedClockSkewMs ;
38
35
}
39
- if ( strategy . settings . attributeConsumingServiceIndex ) {
36
+ if ( strategy . settings . attributeConsumingServiceIndex ) {
40
37
options . attributeConsumingServiceIndex = strategy . settings . attributeConsumingServiceIndex ;
41
38
}
42
- if ( strategy . settings . disableRequestedAuthnContext ) {
39
+ if ( strategy . settings . disableRequestedAuthnContext ) {
43
40
options . disableRequestedAuthnContext = strategy . settings . disableRequestedAuthnContext ;
44
41
}
45
- if ( strategy . settings . authnContext ) {
42
+ if ( strategy . settings . authnContext ) {
46
43
options . authnContext = strategy . settings . authnContext ;
47
44
}
48
- if ( strategy . settings . forceAuthn ) {
45
+ if ( strategy . settings . forceAuthn ) {
49
46
options . forceAuthn = strategy . settings . forceAuthn ;
50
47
}
51
- if ( strategy . settings . skipRequestCompression ) {
48
+ if ( strategy . settings . skipRequestCompression ) {
52
49
options . skipRequestCompression = strategy . settings . skipRequestCompression ;
53
50
}
54
- if ( strategy . settings . authnRequestBinding ) {
51
+ if ( strategy . settings . authnRequestBinding ) {
55
52
options . authnRequestBinding = strategy . settings . authnRequestBinding ;
56
53
}
57
- if ( strategy . settings . RACComparison ) {
54
+ if ( strategy . settings . RACComparison ) {
58
55
options . RACComparison = strategy . settings . RACComparison ;
59
56
}
60
- if ( strategy . settings . providerName ) {
57
+ if ( strategy . settings . providerName ) {
61
58
options . providerName = strategy . settings . providerName ;
62
59
}
63
- if ( strategy . settings . idpIssuer ) {
60
+ if ( strategy . settings . idpIssuer ) {
64
61
options . idpIssuer = strategy . settings . idpIssuer ;
65
62
}
66
- if ( strategy . settings . validateInResponseTo ) {
63
+ if ( strategy . settings . validateInResponseTo ) {
67
64
options . validateInResponseTo = strategy . settings . validateInResponseTo ;
68
65
}
69
- if ( strategy . settings . requestIdExpirationPeriodMs ) {
66
+ if ( strategy . settings . requestIdExpirationPeriodMs ) {
70
67
options . requestIdExpirationPeriodMs = strategy . settings . requestIdExpirationPeriodMs ;
71
68
}
72
- if ( strategy . settings . logoutUrl ) {
69
+ if ( strategy . settings . logoutUrl ) {
73
70
options . logoutUrl = strategy . settings . logoutUrl ;
74
71
}
75
72
@@ -220,19 +217,10 @@ function setDefaults(strategy) {
220
217
function initialize ( strategy ) {
221
218
const app = AuthenticationInitializer . app ;
222
219
const passport = AuthenticationInitializer . passport ;
223
- const provision = AuthenticationInitializer . provision ;
224
220
225
221
setDefaults ( strategy ) ;
226
222
configure ( strategy ) ;
227
223
228
- function parseLoginMetadata ( req , res , next ) {
229
- req . loginOptions = {
230
- userAgent : req . headers [ 'user-agent' ] ,
231
- appVersion : req . param ( 'appVersion' )
232
- } ;
233
-
234
- next ( ) ;
235
- }
236
224
app . get (
237
225
'/auth/' + strategy . name + '/signin' ,
238
226
function ( req , res , next ) {
@@ -246,83 +234,6 @@ function initialize(strategy) {
246
234
} ) ( req , res , next ) ;
247
235
}
248
236
) ;
249
-
250
- // DEPRECATED retain old routes as deprecated until next major version.
251
- // Create a new device
252
- // Any authenticated user can create a new device, the registered field
253
- // will be set to false.
254
- app . post ( '/auth/' + strategy . name + '/devices' ,
255
- function ( req , res , next ) {
256
- if ( req . user ) {
257
- next ( ) ;
258
- } else {
259
- res . sendStatus ( 401 ) ;
260
- }
261
- } ,
262
- function ( req , res , next ) {
263
- const newDevice = {
264
- uid : req . param ( 'uid' ) ,
265
- name : req . param ( 'name' ) ,
266
- registered : false ,
267
- description : req . param ( 'description' ) ,
268
- userAgent : req . headers [ 'user-agent' ] ,
269
- appVersion : req . param ( 'appVersion' ) ,
270
- userId : req . user . id
271
- } ;
272
-
273
- Device . getDeviceByUid ( newDevice . uid )
274
- . then ( device => {
275
- if ( device ) {
276
- // already exists, do not register
277
- return res . json ( device ) ;
278
- }
279
-
280
- Device . createDevice ( newDevice )
281
- . then ( device => res . json ( device ) )
282
- . catch ( err => next ( err ) ) ;
283
- } )
284
- . catch ( err => next ( err ) ) ;
285
- }
286
- ) ;
287
-
288
- // DEPRECATED session authorization, remove in next version.
289
- app . post (
290
- '/auth/' + strategy . name + '/authorize' ,
291
- function ( req , res , next ) {
292
- if ( req . user ) {
293
- log . warn ( 'session authorization is deprecated, please use jwt' ) ;
294
- return next ( ) ;
295
- }
296
-
297
- passport . authenticate ( 'authorization' , function ( err , user , info = { } ) {
298
- if ( ! user ) return res . status ( 401 ) . send ( info . message ) ;
299
-
300
- req . user = user ;
301
- next ( ) ;
302
- } ) ( req , res , next ) ;
303
- } ,
304
- provision . check ( strategy . name ) ,
305
- parseLoginMetadata ,
306
- function ( req , res , next ) {
307
- new api . User ( ) . login ( req . user , req . provisionedDevice , req . loginOptions , function ( err , token ) {
308
- if ( err ) return next ( err ) ;
309
-
310
- authenticationApiAppender . append ( strategy . api ) . then ( api => {
311
- res . json ( {
312
- token : token . token ,
313
- expirationDate : token . expirationDate ,
314
- user : userTransformer . transform ( req . user , { path : req . getRoot ( ) } ) ,
315
- device : req . provisionedDevice ,
316
- api : api
317
- } ) ;
318
- } ) . catch ( err => {
319
- next ( err ) ;
320
- } ) ;
321
- } ) ;
322
-
323
- req . session = null ;
324
- }
325
- ) ;
326
237
}
327
238
328
239
module . exports = {
0 commit comments