Skip to content

Commit 2b10130

Browse files
committed
move array creation to route setup, clean up the loop a little
1 parent d1604e8 commit 2b10130

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

lib/auth.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ internals.Auth.prototype._setupRoute = function (options, path) {
125125
options = Hoek.applyToDefaults(this.settings.default, options);
126126
}
127127

128+
if (typeof options.scope === 'string') {
129+
options.scope = [options.scope];
130+
}
131+
128132
Hoek.assert(options.strategies.length, 'Route missing authentication strategy:', path);
129133

130134
options.mode = options.mode || 'required';
@@ -269,25 +273,18 @@ internals.Auth.prototype._authenticate = function (request, next) {
269273

270274
// Check scope
271275

272-
var expandScope = function (scope) {
273-
274-
return scope.replace(/{([^{}]+)}/g, function (_, context) {
276+
if (config.scope) {
277+
var expandScope = function (_, context) {
275278

276279
return Hoek.reach({
277280
params: request.params,
278281
query: request.query,
279282
payload: request.payload
280283
}, context);
281-
});
282-
};
283-
284-
if (config.scope) {
285-
if (typeof config.scope === 'string') {
286-
config.scope = [config.scope];
287-
}
284+
};
288285

289286
for (var i = 0, il = config.scope.length; i < il; ++i) {
290-
config.scope[i] = expandScope(config.scope[i]);
287+
config.scope[i] = config.scope[i].replace(/{([^{}]+)}/g, expandScope);
291288
}
292289

293290
if (!credentials.scope ||

0 commit comments

Comments
 (0)