@@ -129,6 +129,15 @@ internals.Auth.prototype._setupRoute = function (options, path) {
129
129
options . scope = [ options . scope ] ;
130
130
}
131
131
132
+ if ( options . scope ) {
133
+ for ( var i = 0 , il = options . scope . length ; i < il ; ++ i ) {
134
+ if ( / { ( [ ^ { } ] + ) } / g. test ( options . scope [ i ] ) ) {
135
+ options . hasScopeParameters = true ;
136
+ break ;
137
+ }
138
+ }
139
+ }
140
+
132
141
Hoek . assert ( options . strategies . length , 'Route missing authentication strategy:' , path ) ;
133
142
134
143
options . mode = options . mode || 'required' ;
@@ -274,17 +283,19 @@ internals.Auth.prototype._authenticate = function (request, next) {
274
283
// Check scope
275
284
276
285
if ( config . scope ) {
277
- var expandScope = function ( _ , context ) {
278
-
279
- return Hoek . reach ( {
280
- params : request . params ,
281
- query : request . query ,
282
- payload : request . payload
283
- } , context ) ;
284
- } ;
285
-
286
- for ( var i = 0 , il = config . scope . length ; i < il ; ++ i ) {
287
- config . scope [ i ] = config . scope [ i ] . replace ( / { ( [ ^ { } ] + ) } / g, expandScope ) ;
286
+ if ( config . hasScopeParameters ) {
287
+ var expandScope = function ( _ , context ) {
288
+
289
+ return Hoek . reach ( {
290
+ params : request . params ,
291
+ query : request . query ,
292
+ payload : request . payload
293
+ } , context ) ;
294
+ } ;
295
+
296
+ for ( var i = 0 , il = config . scope . length ; i < il ; ++ i ) {
297
+ config . scope [ i ] = config . scope [ i ] . replace ( / { ( [ ^ { } ] + ) } / g, expandScope ) ;
298
+ }
288
299
}
289
300
290
301
if ( ! credentials . scope ||
0 commit comments