The session scope will not match the auth.scope if auth scope is an array and the session scope is more than one character.
Here are three test examples.
This works but we are only match one character.
// Success
it('matches scope array item', function (done) {
var server = new Hapi.Server();
server.auth.scheme('custom', internals.implementation);
server.auth.strategy('default', 'custom', true, { users: { steve: { scope: 'a' } } });
server.route({
method: 'GET',
path: '/',
config: {
handler: function (request, reply) { reply(request.auth.credentials.user); },
auth: {
scope: ['a', 'c']
}
}
});
server.inject({ url: '/', headers: { authorization: 'Custom steve' } }, function (res) {
expect(res.statusCode).to.equal(200);
done();
});
});
This works with user scope an array match and the match is more than one character.
// Success
it('matches scope array item', function (done) {
var server = new Hapi.Server();
server.auth.scheme('custom', internals.implementation);
server.auth.strategy('default', 'custom', true, { users: { steve: { scope: ['ab', 'cat'] } } });
server.route({
method: 'GET',
path: '/',
config: {
handler: function (request, reply) { reply(request.auth.credentials.user); },
auth: {
scope: ['ab', 'cat']
}
}
});
server.inject({ url: '/', headers: { authorization: 'Custom steve' } }, function (res) {
expect(res.statusCode).to.equal(200);
done();
});
});
This fails, the user scope is not an array and the match needs to be more than one character.
// Failed
it('matches scope array item', function (done) {
var server = new Hapi.Server();
server.auth.scheme('custom', internals.implementation);
server.auth.strategy('default', 'custom', true, { users: { steve: { scope: 'ab' } } });
server.route({
method: 'GET',
path: '/',
config: {
handler: function (request, reply) { reply(request.auth.credentials.user); },
auth: {
scope: ['ab', 'cat']
}
}
});
server.inject({ url: '/', headers: { authorization: 'Custom steve' } }, function (res) {
expect(res.statusCode).to.equal(200);
done();
});
});
The session scope will not match the auth.scope if auth scope is an array and the session scope is more than one character.
Here are three test examples.
This works but we are only match one character.
This works with user scope an array match and the match is more than one character.
This fails, the user scope is not an array and the match needs to be more than one character.