Skip to content

Commit 8baad90

Browse files
committed
set a flag if the scope has parameters and only call replace in that case
1 parent 2b10130 commit 8baad90

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

lib/auth.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ internals.Auth.prototype._setupRoute = function (options, path) {
129129
options.scope = [options.scope];
130130
}
131131

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+
132141
Hoek.assert(options.strategies.length, 'Route missing authentication strategy:', path);
133142

134143
options.mode = options.mode || 'required';
@@ -274,17 +283,19 @@ internals.Auth.prototype._authenticate = function (request, next) {
274283
// Check scope
275284

276285
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+
}
288299
}
289300

290301
if (!credentials.scope ||

0 commit comments

Comments
 (0)