UNPKG

815 BJavaScriptView Raw
1'use strict';
2
3var assert = require('assert-plus');
4var Promise = require('bluebird');
5var authErrors = require('./errors');
6
7module.exports = function RemoteUserAuthority(authScope, authentic, logger) {
8 assert.object(authScope, 'authScope');
9 assert.object(authentic, 'authentic');
10 assert.object(logger, 'logger');
11
12 var common = require('./common')(authScope, authentic, logger, 0);
13
14 authScope = Promise.promisifyAll(authScope);
15 var create = function(sig) {
16 if (!sig || !sig.params || !sig.params.jwt) {
17 return Promise.resolve();
18 }
19 return authScope.verifyAsync(sig.params.jwt)
20 .then(common.verifyContext)
21 .catch(authErrors.UnverifiedContextError, function(){
22 })
23 .catch(authErrors.ExpiredContextError, function(){
24 });
25 };
26
27 return { create: create };
28};