@@ -2,18 +2,15 @@ const SamlStrategy = require('@node-saml/passport-saml').Strategy
22 , log = require ( 'winston' )
33 , User = require ( '../models/user' )
44 , Role = require ( '../models/role' )
5- , Device = require ( '../models/device' )
65 , TokenAssertion = require ( './verification' ) . TokenAssertion
76 , api = require ( '../api' )
8- , userTransformer = require ( '../transformers/user' )
9- , AuthenticationInitializer = require ( './index' )
10- , authenticationApiAppender = require ( '../utilities/authenticationApiAppender' ) ;
7+ , AuthenticationInitializer = require ( './index' ) ;
118
129function configure ( strategy ) {
1310 log . info ( 'Configuring ' + strategy . title + ' authentication' ) ;
1411
1512 const options = {
16- path : `/auth/${ strategy . name } /callback` ,
13+ callbackUrl : `${ strategy . redirectHost } /auth/${ strategy . name } /callback` ,
1714 entryPoint : strategy . settings . entryPoint ,
1815 cert : strategy . settings . cert ,
1916 issuer : strategy . settings . issuer
@@ -27,49 +24,49 @@ function configure(strategy) {
2724 if ( strategy . settings . signatureAlgorithm ) {
2825 options . signatureAlgorithm = strategy . settings . signatureAlgorithm ;
2926 }
30- if ( strategy . settings . audience ) {
27+ if ( strategy . settings . audience ) {
3128 options . audience = strategy . settings . audience ;
3229 }
33- if ( strategy . settings . identifierFormat ) {
30+ if ( strategy . settings . identifierFormat ) {
3431 options . identifierFormat = strategy . settings . identifierFormat ;
3532 }
36- if ( strategy . settings . acceptedClockSkewMs ) {
33+ if ( strategy . settings . acceptedClockSkewMs ) {
3734 options . acceptedClockSkewMs = strategy . settings . acceptedClockSkewMs ;
3835 }
39- if ( strategy . settings . attributeConsumingServiceIndex ) {
36+ if ( strategy . settings . attributeConsumingServiceIndex ) {
4037 options . attributeConsumingServiceIndex = strategy . settings . attributeConsumingServiceIndex ;
4138 }
42- if ( strategy . settings . disableRequestedAuthnContext ) {
39+ if ( strategy . settings . disableRequestedAuthnContext ) {
4340 options . disableRequestedAuthnContext = strategy . settings . disableRequestedAuthnContext ;
4441 }
45- if ( strategy . settings . authnContext ) {
42+ if ( strategy . settings . authnContext ) {
4643 options . authnContext = strategy . settings . authnContext ;
4744 }
48- if ( strategy . settings . forceAuthn ) {
45+ if ( strategy . settings . forceAuthn ) {
4946 options . forceAuthn = strategy . settings . forceAuthn ;
5047 }
51- if ( strategy . settings . skipRequestCompression ) {
48+ if ( strategy . settings . skipRequestCompression ) {
5249 options . skipRequestCompression = strategy . settings . skipRequestCompression ;
5350 }
54- if ( strategy . settings . authnRequestBinding ) {
51+ if ( strategy . settings . authnRequestBinding ) {
5552 options . authnRequestBinding = strategy . settings . authnRequestBinding ;
5653 }
57- if ( strategy . settings . RACComparison ) {
54+ if ( strategy . settings . RACComparison ) {
5855 options . RACComparison = strategy . settings . RACComparison ;
5956 }
60- if ( strategy . settings . providerName ) {
57+ if ( strategy . settings . providerName ) {
6158 options . providerName = strategy . settings . providerName ;
6259 }
63- if ( strategy . settings . idpIssuer ) {
60+ if ( strategy . settings . idpIssuer ) {
6461 options . idpIssuer = strategy . settings . idpIssuer ;
6562 }
66- if ( strategy . settings . validateInResponseTo ) {
63+ if ( strategy . settings . validateInResponseTo ) {
6764 options . validateInResponseTo = strategy . settings . validateInResponseTo ;
6865 }
69- if ( strategy . settings . requestIdExpirationPeriodMs ) {
66+ if ( strategy . settings . requestIdExpirationPeriodMs ) {
7067 options . requestIdExpirationPeriodMs = strategy . settings . requestIdExpirationPeriodMs ;
7168 }
72- if ( strategy . settings . logoutUrl ) {
69+ if ( strategy . settings . logoutUrl ) {
7370 options . logoutUrl = strategy . settings . logoutUrl ;
7471 }
7572
@@ -220,19 +217,10 @@ function setDefaults(strategy) {
220217function initialize ( strategy ) {
221218 const app = AuthenticationInitializer . app ;
222219 const passport = AuthenticationInitializer . passport ;
223- const provision = AuthenticationInitializer . provision ;
224220
225221 setDefaults ( strategy ) ;
226222 configure ( strategy ) ;
227223
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- }
236224 app . get (
237225 '/auth/' + strategy . name + '/signin' ,
238226 function ( req , res , next ) {
@@ -246,83 +234,6 @@ function initialize(strategy) {
246234 } ) ( req , res , next ) ;
247235 }
248236 ) ;
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- ) ;
326237}
327238
328239module . exports = {
0 commit comments