@icgc-argo/ego-token-utils
Advanced tools
Comparing version 3.4.0 to 4.0.0
@@ -109,3 +109,3 @@ /** | ||
}; | ||
var DCC_PREFIX = 'program-service.WRITE'; | ||
var DCC_PREFIX = 'PROGRAMSERVICE.WRITE'; | ||
var RDPC_PREFIX = 'RDPC-'; | ||
@@ -125,3 +125,3 @@ var PROGRAM_PREFIX = 'PROGRAM-'; | ||
*/ | ||
var decodeToken = function (egoJwt) { return jwtDecode(egoJwt); }; | ||
var decodeToken = function (egoPublicKey) { return function (egoJwt) { return jwtDecode(egoJwt); }; }; | ||
/** | ||
@@ -132,3 +132,3 @@ * checks if a given jwt is valid and has not expired. | ||
*/ | ||
var isValidJwt = function (egoJwt) { | ||
var isValidJwt = function (egoPublicKey) { return function (egoJwt) { | ||
try { | ||
@@ -139,3 +139,3 @@ if (!egoJwt) { | ||
else { | ||
var exp = decodeToken(egoJwt).exp; | ||
var exp = decodeToken(egoPublicKey)(egoJwt).exp; | ||
return exp * 1000 > Date.now(); | ||
@@ -147,3 +147,3 @@ } | ||
} | ||
}; | ||
}; }; | ||
/** | ||
@@ -153,5 +153,5 @@ * check if a given jwt has dcc access | ||
*/ | ||
var isDccMember = function (egoJwt) { | ||
var isDccMember = function (egoPublicKey) { return function (egoJwt) { | ||
try { | ||
var data = decodeToken(egoJwt); | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -163,3 +163,3 @@ return permissions.some(function (p) { return p.includes(DCC_PREFIX); }); | ||
} | ||
}; | ||
}; }; | ||
/** | ||
@@ -169,5 +169,5 @@ * check if a given jwt has rdpc access | ||
*/ | ||
var isRdpcMember = function (egoJwt) { | ||
var isRdpcMember = function (egoPublicKey) { return function (egoJwt) { | ||
try { | ||
var data = decodeToken(egoJwt); | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -186,3 +186,3 @@ var rdpcPermissions = permissions.filter(function (p) { | ||
} | ||
}; | ||
}; }; | ||
/** | ||
@@ -221,4 +221,4 @@ * takes a scope string and returns an object for interpretation | ||
*/ | ||
var getReadableProgramScopes = function (egoJwt) { | ||
var data = decodeToken(egoJwt); | ||
var getReadableProgramScopes = function (egoPublicKey) { return function (egoJwt) { | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -236,3 +236,3 @@ var programPermissions = permissions.filter(function (p) { | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -243,4 +243,4 @@ * get an array of PermissionScopeObj which gives at least `.WRITE` permission to the token | ||
*/ | ||
var getWriteableProgramScopes = function (egoJwt) { | ||
var data = decodeToken(egoJwt); | ||
var getWriteableProgramScopes = function (egoPublicKey) { return function (egoJwt) { | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -258,3 +258,3 @@ var programPermissions = permissions.filter(function (p) { | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -265,8 +265,8 @@ * get an array of program short names where the user has been given at least `.READ` permission | ||
*/ | ||
var getReadableProgramShortNames = function (egoJwt) { | ||
return getReadableProgramScopes(egoJwt).map(function (_a) { | ||
var getReadableProgramShortNames = function (egoPublicKey) { return function (egoJwt) { | ||
return getReadableProgramScopes(egoPublicKey)(egoJwt).map(function (_a) { | ||
var policy = _a.policy; | ||
return policy.replace(PROGRAM_PREFIX, ''); | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -277,8 +277,8 @@ * get an array of program short names where the user has been given at least `.READ` permission | ||
*/ | ||
var getWriteableProgramShortNames = function (egoJwt) { | ||
return getWriteableProgramScopes(egoJwt).map(function (_a) { | ||
var getWriteableProgramShortNames = function (egoPublicKey) { return function (egoJwt) { | ||
return getWriteableProgramScopes(egoPublicKey)(egoJwt).map(function (_a) { | ||
var policy = _a.policy; | ||
return policy.replace(PROGRAM_PREFIX, ''); | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -288,4 +288,4 @@ * check if a given JWT can read program with given id | ||
*/ | ||
var canReadProgram = function (args) { | ||
var authorizedProgramScopes = getReadableProgramScopes(args.egoJwt); | ||
var canReadProgram = function (egoPublicKey) { return function (args) { | ||
var authorizedProgramScopes = getReadableProgramScopes(egoPublicKey)(args.egoJwt); | ||
var programIds = authorizedProgramScopes.map(function (_a) { | ||
@@ -295,4 +295,4 @@ var policy = _a.policy; | ||
}); | ||
return isDccMember(args.egoJwt) || programIds.some(function (id) { return id === args.programId; }); | ||
}; | ||
return isDccMember(egoPublicKey)(args.egoJwt) || programIds.some(function (id) { return id === args.programId; }); | ||
}; }; | ||
/** | ||
@@ -302,5 +302,5 @@ * check if a given JWT can write program with given id | ||
*/ | ||
var canWriteProgram = function (args) { | ||
var authorizedProgramScopes = getReadableProgramScopes(args.egoJwt); | ||
return (isDccMember(args.egoJwt) || | ||
var canWriteProgram = function (egoPublicKey) { return function (args) { | ||
var authorizedProgramScopes = getReadableProgramScopes(egoPublicKey)(args.egoJwt); | ||
return (isDccMember(egoPublicKey)(args.egoJwt) || | ||
authorizedProgramScopes.some(function (_a) { | ||
@@ -311,3 +311,3 @@ var policy = _a.policy, permission = _a.permission; | ||
})); | ||
}; | ||
}; }; | ||
/** | ||
@@ -317,5 +317,5 @@ * checks if a given token can read any program at all | ||
*/ | ||
var canReadSomeProgram = function (egoJwt) { | ||
return isDccMember(egoJwt) || !!getReadableProgramScopes(egoJwt).length; | ||
}; | ||
var canReadSomeProgram = function (egoPublicKey) { return function (egoJwt) { | ||
return (isDccMember(egoPublicKey)(egoJwt) || !!getReadableProgramScopes(egoPublicKey)(egoJwt).length); | ||
}; }; | ||
/** | ||
@@ -325,5 +325,5 @@ * checks if a given token can write to any program at all | ||
*/ | ||
var canWriteSomeProgram = function (egoJwt) { | ||
return isDccMember(egoJwt) || !!getWriteableProgramScopes(egoJwt).length; | ||
}; | ||
var canWriteSomeProgram = function (egoPublicKey) { return function (egoJwt) { | ||
return (isDccMember(egoPublicKey)(egoJwt) || !!getWriteableProgramScopes(egoPublicKey)(egoJwt).length); | ||
}; }; | ||
/** | ||
@@ -333,26 +333,23 @@ * check if a given JWT has admin access to program with given id | ||
*/ | ||
var isProgramAdmin = function (args) { | ||
return canWriteProgram(args); | ||
}; | ||
var egoTokenUtils = { | ||
var isProgramAdmin = function (egoPublicKey) { return function (args) { return canWriteProgram(egoPublicKey)(args); }; }; | ||
var egoTokenUtils = (function (egoPublicKey) { return ({ | ||
serializeScope: serializeScope, | ||
parseScope: parseScope, | ||
isPermission: isPermission, | ||
decodeToken: decodeToken, | ||
isValidJwt: isValidJwt, | ||
isDccMember: isDccMember, | ||
isRdpcMember: isRdpcMember, | ||
parseScope: parseScope, | ||
serializeScope: serializeScope, | ||
getReadableProgramScopes: getReadableProgramScopes, | ||
getWriteableProgramScopes: getWriteableProgramScopes, | ||
canReadProgram: canReadProgram, | ||
canWriteProgram: canWriteProgram, | ||
isProgramAdmin: isProgramAdmin, | ||
canReadSomeProgram: canReadSomeProgram, | ||
canWriteSomeProgram: canWriteSomeProgram, | ||
getReadableProgramShortNames: getReadableProgramShortNames, | ||
getWriteableProgramShortNames: getWriteableProgramShortNames | ||
}; | ||
decodeToken: decodeToken(egoPublicKey), | ||
isValidJwt: isValidJwt(egoPublicKey), | ||
isDccMember: isDccMember(egoPublicKey), | ||
isRdpcMember: isRdpcMember(egoPublicKey), | ||
getReadableProgramScopes: getReadableProgramScopes(egoPublicKey), | ||
getWriteableProgramScopes: getWriteableProgramScopes(egoPublicKey), | ||
canReadProgram: canReadProgram(egoPublicKey), | ||
canWriteProgram: canWriteProgram(egoPublicKey), | ||
isProgramAdmin: isProgramAdmin(egoPublicKey), | ||
canReadSomeProgram: canReadSomeProgram(egoPublicKey), | ||
canWriteSomeProgram: canWriteSomeProgram(egoPublicKey), | ||
getReadableProgramShortNames: getReadableProgramShortNames(egoPublicKey), | ||
getWriteableProgramShortNames: getWriteableProgramShortNames(egoPublicKey) | ||
}); }); | ||
export default egoTokenUtils; | ||
export { isPermission, decodeToken, isValidJwt, isDccMember, isRdpcMember, parseScope, serializeScope, getReadableProgramScopes, getWriteableProgramScopes, getReadableProgramShortNames, getWriteableProgramShortNames, canReadProgram, canWriteProgram, canReadSomeProgram, canWriteSomeProgram, isProgramAdmin }; | ||
//# sourceMappingURL=ego-token-utils.es5.js.map |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.egoTokenUtils = {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.egoTokenUtils = factory()); | ||
}(this, (function () { 'use strict'; | ||
@@ -115,3 +115,3 @@ /** | ||
}; | ||
var DCC_PREFIX = 'program-service.WRITE'; | ||
var DCC_PREFIX = 'PROGRAMSERVICE.WRITE'; | ||
var RDPC_PREFIX = 'RDPC-'; | ||
@@ -131,3 +131,3 @@ var PROGRAM_PREFIX = 'PROGRAM-'; | ||
*/ | ||
var decodeToken = function (egoJwt) { return jwtDecode(egoJwt); }; | ||
var decodeToken = function (egoPublicKey) { return function (egoJwt) { return jwtDecode(egoJwt); }; }; | ||
/** | ||
@@ -138,3 +138,3 @@ * checks if a given jwt is valid and has not expired. | ||
*/ | ||
var isValidJwt = function (egoJwt) { | ||
var isValidJwt = function (egoPublicKey) { return function (egoJwt) { | ||
try { | ||
@@ -145,3 +145,3 @@ if (!egoJwt) { | ||
else { | ||
var exp = decodeToken(egoJwt).exp; | ||
var exp = decodeToken(egoPublicKey)(egoJwt).exp; | ||
return exp * 1000 > Date.now(); | ||
@@ -153,3 +153,3 @@ } | ||
} | ||
}; | ||
}; }; | ||
/** | ||
@@ -159,5 +159,5 @@ * check if a given jwt has dcc access | ||
*/ | ||
var isDccMember = function (egoJwt) { | ||
var isDccMember = function (egoPublicKey) { return function (egoJwt) { | ||
try { | ||
var data = decodeToken(egoJwt); | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -169,3 +169,3 @@ return permissions.some(function (p) { return p.includes(DCC_PREFIX); }); | ||
} | ||
}; | ||
}; }; | ||
/** | ||
@@ -175,5 +175,5 @@ * check if a given jwt has rdpc access | ||
*/ | ||
var isRdpcMember = function (egoJwt) { | ||
var isRdpcMember = function (egoPublicKey) { return function (egoJwt) { | ||
try { | ||
var data = decodeToken(egoJwt); | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -192,3 +192,3 @@ var rdpcPermissions = permissions.filter(function (p) { | ||
} | ||
}; | ||
}; }; | ||
/** | ||
@@ -227,4 +227,4 @@ * takes a scope string and returns an object for interpretation | ||
*/ | ||
var getReadableProgramScopes = function (egoJwt) { | ||
var data = decodeToken(egoJwt); | ||
var getReadableProgramScopes = function (egoPublicKey) { return function (egoJwt) { | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -242,3 +242,3 @@ var programPermissions = permissions.filter(function (p) { | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -249,4 +249,4 @@ * get an array of PermissionScopeObj which gives at least `.WRITE` permission to the token | ||
*/ | ||
var getWriteableProgramScopes = function (egoJwt) { | ||
var data = decodeToken(egoJwt); | ||
var getWriteableProgramScopes = function (egoPublicKey) { return function (egoJwt) { | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -264,3 +264,3 @@ var programPermissions = permissions.filter(function (p) { | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -271,8 +271,8 @@ * get an array of program short names where the user has been given at least `.READ` permission | ||
*/ | ||
var getReadableProgramShortNames = function (egoJwt) { | ||
return getReadableProgramScopes(egoJwt).map(function (_a) { | ||
var getReadableProgramShortNames = function (egoPublicKey) { return function (egoJwt) { | ||
return getReadableProgramScopes(egoPublicKey)(egoJwt).map(function (_a) { | ||
var policy = _a.policy; | ||
return policy.replace(PROGRAM_PREFIX, ''); | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -283,8 +283,8 @@ * get an array of program short names where the user has been given at least `.READ` permission | ||
*/ | ||
var getWriteableProgramShortNames = function (egoJwt) { | ||
return getWriteableProgramScopes(egoJwt).map(function (_a) { | ||
var getWriteableProgramShortNames = function (egoPublicKey) { return function (egoJwt) { | ||
return getWriteableProgramScopes(egoPublicKey)(egoJwt).map(function (_a) { | ||
var policy = _a.policy; | ||
return policy.replace(PROGRAM_PREFIX, ''); | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -294,4 +294,4 @@ * check if a given JWT can read program with given id | ||
*/ | ||
var canReadProgram = function (args) { | ||
var authorizedProgramScopes = getReadableProgramScopes(args.egoJwt); | ||
var canReadProgram = function (egoPublicKey) { return function (args) { | ||
var authorizedProgramScopes = getReadableProgramScopes(egoPublicKey)(args.egoJwt); | ||
var programIds = authorizedProgramScopes.map(function (_a) { | ||
@@ -301,4 +301,4 @@ var policy = _a.policy; | ||
}); | ||
return isDccMember(args.egoJwt) || programIds.some(function (id) { return id === args.programId; }); | ||
}; | ||
return isDccMember(egoPublicKey)(args.egoJwt) || programIds.some(function (id) { return id === args.programId; }); | ||
}; }; | ||
/** | ||
@@ -308,5 +308,5 @@ * check if a given JWT can write program with given id | ||
*/ | ||
var canWriteProgram = function (args) { | ||
var authorizedProgramScopes = getReadableProgramScopes(args.egoJwt); | ||
return (isDccMember(args.egoJwt) || | ||
var canWriteProgram = function (egoPublicKey) { return function (args) { | ||
var authorizedProgramScopes = getReadableProgramScopes(egoPublicKey)(args.egoJwt); | ||
return (isDccMember(egoPublicKey)(args.egoJwt) || | ||
authorizedProgramScopes.some(function (_a) { | ||
@@ -317,3 +317,3 @@ var policy = _a.policy, permission = _a.permission; | ||
})); | ||
}; | ||
}; }; | ||
/** | ||
@@ -323,5 +323,5 @@ * checks if a given token can read any program at all | ||
*/ | ||
var canReadSomeProgram = function (egoJwt) { | ||
return isDccMember(egoJwt) || !!getReadableProgramScopes(egoJwt).length; | ||
}; | ||
var canReadSomeProgram = function (egoPublicKey) { return function (egoJwt) { | ||
return (isDccMember(egoPublicKey)(egoJwt) || !!getReadableProgramScopes(egoPublicKey)(egoJwt).length); | ||
}; }; | ||
/** | ||
@@ -331,5 +331,5 @@ * checks if a given token can write to any program at all | ||
*/ | ||
var canWriteSomeProgram = function (egoJwt) { | ||
return isDccMember(egoJwt) || !!getWriteableProgramScopes(egoJwt).length; | ||
}; | ||
var canWriteSomeProgram = function (egoPublicKey) { return function (egoJwt) { | ||
return (isDccMember(egoPublicKey)(egoJwt) || !!getWriteableProgramScopes(egoPublicKey)(egoJwt).length); | ||
}; }; | ||
/** | ||
@@ -339,45 +339,25 @@ * check if a given JWT has admin access to program with given id | ||
*/ | ||
var isProgramAdmin = function (args) { | ||
return canWriteProgram(args); | ||
}; | ||
var egoTokenUtils = { | ||
var isProgramAdmin = function (egoPublicKey) { return function (args) { return canWriteProgram(egoPublicKey)(args); }; }; | ||
var egoTokenUtils = (function (egoPublicKey) { return ({ | ||
serializeScope: serializeScope, | ||
parseScope: parseScope, | ||
isPermission: isPermission, | ||
decodeToken: decodeToken, | ||
isValidJwt: isValidJwt, | ||
isDccMember: isDccMember, | ||
isRdpcMember: isRdpcMember, | ||
parseScope: parseScope, | ||
serializeScope: serializeScope, | ||
getReadableProgramScopes: getReadableProgramScopes, | ||
getWriteableProgramScopes: getWriteableProgramScopes, | ||
canReadProgram: canReadProgram, | ||
canWriteProgram: canWriteProgram, | ||
isProgramAdmin: isProgramAdmin, | ||
canReadSomeProgram: canReadSomeProgram, | ||
canWriteSomeProgram: canWriteSomeProgram, | ||
getReadableProgramShortNames: getReadableProgramShortNames, | ||
getWriteableProgramShortNames: getWriteableProgramShortNames | ||
}; | ||
decodeToken: decodeToken(egoPublicKey), | ||
isValidJwt: isValidJwt(egoPublicKey), | ||
isDccMember: isDccMember(egoPublicKey), | ||
isRdpcMember: isRdpcMember(egoPublicKey), | ||
getReadableProgramScopes: getReadableProgramScopes(egoPublicKey), | ||
getWriteableProgramScopes: getWriteableProgramScopes(egoPublicKey), | ||
canReadProgram: canReadProgram(egoPublicKey), | ||
canWriteProgram: canWriteProgram(egoPublicKey), | ||
isProgramAdmin: isProgramAdmin(egoPublicKey), | ||
canReadSomeProgram: canReadSomeProgram(egoPublicKey), | ||
canWriteSomeProgram: canWriteSomeProgram(egoPublicKey), | ||
getReadableProgramShortNames: getReadableProgramShortNames(egoPublicKey), | ||
getWriteableProgramShortNames: getWriteableProgramShortNames(egoPublicKey) | ||
}); }); | ||
exports.isPermission = isPermission; | ||
exports.decodeToken = decodeToken; | ||
exports.isValidJwt = isValidJwt; | ||
exports.isDccMember = isDccMember; | ||
exports.isRdpcMember = isRdpcMember; | ||
exports.parseScope = parseScope; | ||
exports.serializeScope = serializeScope; | ||
exports.getReadableProgramScopes = getReadableProgramScopes; | ||
exports.getWriteableProgramScopes = getWriteableProgramScopes; | ||
exports.getReadableProgramShortNames = getReadableProgramShortNames; | ||
exports.getWriteableProgramShortNames = getWriteableProgramShortNames; | ||
exports.canReadProgram = canReadProgram; | ||
exports.canWriteProgram = canWriteProgram; | ||
exports.canReadSomeProgram = canReadSomeProgram; | ||
exports.canWriteSomeProgram = canWriteSomeProgram; | ||
exports.isProgramAdmin = isProgramAdmin; | ||
exports.default = egoTokenUtils; | ||
return egoTokenUtils; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=ego-token-utils.umd.js.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
}; | ||
var DCC_PREFIX = 'program-service.WRITE'; | ||
var DCC_PREFIX = 'PROGRAMSERVICE.WRITE'; | ||
var RDPC_PREFIX = 'RDPC-'; | ||
@@ -20,3 +20,3 @@ var PROGRAM_PREFIX = 'PROGRAM-'; | ||
*/ | ||
exports.isPermission = function (str) { | ||
var isPermission = function (str) { | ||
return Object.values(PERMISSIONS).includes(str); | ||
@@ -28,3 +28,3 @@ }; | ||
*/ | ||
exports.decodeToken = function (egoJwt) { return jwtDecode(egoJwt); }; | ||
var decodeToken = function (egoPublicKey) { return function (egoJwt) { return jwtDecode(egoJwt); }; }; | ||
/** | ||
@@ -35,3 +35,3 @@ * checks if a given jwt is valid and has not expired. | ||
*/ | ||
exports.isValidJwt = function (egoJwt) { | ||
var isValidJwt = function (egoPublicKey) { return function (egoJwt) { | ||
try { | ||
@@ -42,3 +42,3 @@ if (!egoJwt) { | ||
else { | ||
var exp = exports.decodeToken(egoJwt).exp; | ||
var exp = decodeToken(egoPublicKey)(egoJwt).exp; | ||
return exp * 1000 > Date.now(); | ||
@@ -50,3 +50,3 @@ } | ||
} | ||
}; | ||
}; }; | ||
/** | ||
@@ -56,5 +56,5 @@ * check if a given jwt has dcc access | ||
*/ | ||
exports.isDccMember = function (egoJwt) { | ||
var isDccMember = function (egoPublicKey) { return function (egoJwt) { | ||
try { | ||
var data = exports.decodeToken(egoJwt); | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -66,3 +66,3 @@ return permissions.some(function (p) { return p.includes(DCC_PREFIX); }); | ||
} | ||
}; | ||
}; }; | ||
/** | ||
@@ -72,5 +72,5 @@ * check if a given jwt has rdpc access | ||
*/ | ||
exports.isRdpcMember = function (egoJwt) { | ||
var isRdpcMember = function (egoPublicKey) { return function (egoJwt) { | ||
try { | ||
var data = exports.decodeToken(egoJwt); | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -89,3 +89,3 @@ var rdpcPermissions = permissions.filter(function (p) { | ||
} | ||
}; | ||
}; }; | ||
/** | ||
@@ -95,5 +95,5 @@ * takes a scope string and returns an object for interpretation | ||
*/ | ||
exports.parseScope = function (scope) { | ||
var parseScope = function (scope) { | ||
var permission = scope.split('.')[1]; | ||
if (exports.isPermission(permission)) { | ||
if (isPermission(permission)) { | ||
return { | ||
@@ -112,4 +112,4 @@ policy: scope.split('.')[0], | ||
*/ | ||
exports.serializeScope = function (scopeObj) { | ||
if (exports.isPermission(scopeObj.permission)) { | ||
var serializeScope = function (scopeObj) { | ||
if (isPermission(scopeObj.permission)) { | ||
return scopeObj.policy + "." + scopeObj.permission; | ||
@@ -126,4 +126,4 @@ } | ||
*/ | ||
exports.getReadableProgramScopes = function (egoJwt) { | ||
var data = exports.decodeToken(egoJwt); | ||
var getReadableProgramScopes = function (egoPublicKey) { return function (egoJwt) { | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -136,3 +136,3 @@ var programPermissions = permissions.filter(function (p) { | ||
return programPermissions | ||
.map(exports.parseScope) | ||
.map(parseScope) | ||
.filter(function (scopeObj) { | ||
@@ -142,3 +142,3 @@ return [PERMISSIONS.READ, PERMISSIONS.WRITE, PERMISSIONS.ADMIN].includes(scopeObj.permission) && | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -149,4 +149,4 @@ * get an array of PermissionScopeObj which gives at least `.WRITE` permission to the token | ||
*/ | ||
exports.getWriteableProgramScopes = function (egoJwt) { | ||
var data = exports.decodeToken(egoJwt); | ||
var getWriteableProgramScopes = function (egoPublicKey) { return function (egoJwt) { | ||
var data = decodeToken(egoPublicKey)(egoJwt); | ||
var permissions = data.context.user.permissions; | ||
@@ -159,3 +159,3 @@ var programPermissions = permissions.filter(function (p) { | ||
return programPermissions | ||
.map(exports.parseScope) | ||
.map(parseScope) | ||
.filter(function (scopeObj) { | ||
@@ -165,3 +165,3 @@ return [PERMISSIONS.WRITE, PERMISSIONS.ADMIN].includes(scopeObj.permission) && | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -172,8 +172,8 @@ * get an array of program short names where the user has been given at least `.READ` permission | ||
*/ | ||
exports.getReadableProgramShortNames = function (egoJwt) { | ||
return exports.getReadableProgramScopes(egoJwt).map(function (_a) { | ||
var getReadableProgramShortNames = function (egoPublicKey) { return function (egoJwt) { | ||
return getReadableProgramScopes(egoPublicKey)(egoJwt).map(function (_a) { | ||
var policy = _a.policy; | ||
return policy.replace(PROGRAM_PREFIX, ''); | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -184,8 +184,8 @@ * get an array of program short names where the user has been given at least `.READ` permission | ||
*/ | ||
exports.getWriteableProgramShortNames = function (egoJwt) { | ||
return exports.getWriteableProgramScopes(egoJwt).map(function (_a) { | ||
var getWriteableProgramShortNames = function (egoPublicKey) { return function (egoJwt) { | ||
return getWriteableProgramScopes(egoPublicKey)(egoJwt).map(function (_a) { | ||
var policy = _a.policy; | ||
return policy.replace(PROGRAM_PREFIX, ''); | ||
}); | ||
}; | ||
}; }; | ||
/** | ||
@@ -195,4 +195,4 @@ * check if a given JWT can read program with given id | ||
*/ | ||
exports.canReadProgram = function (args) { | ||
var authorizedProgramScopes = exports.getReadableProgramScopes(args.egoJwt); | ||
var canReadProgram = function (egoPublicKey) { return function (args) { | ||
var authorizedProgramScopes = getReadableProgramScopes(egoPublicKey)(args.egoJwt); | ||
var programIds = authorizedProgramScopes.map(function (_a) { | ||
@@ -202,4 +202,4 @@ var policy = _a.policy; | ||
}); | ||
return exports.isDccMember(args.egoJwt) || programIds.some(function (id) { return id === args.programId; }); | ||
}; | ||
return isDccMember(egoPublicKey)(args.egoJwt) || programIds.some(function (id) { return id === args.programId; }); | ||
}; }; | ||
/** | ||
@@ -209,5 +209,5 @@ * check if a given JWT can write program with given id | ||
*/ | ||
exports.canWriteProgram = function (args) { | ||
var authorizedProgramScopes = exports.getReadableProgramScopes(args.egoJwt); | ||
return (exports.isDccMember(args.egoJwt) || | ||
var canWriteProgram = function (egoPublicKey) { return function (args) { | ||
var authorizedProgramScopes = getReadableProgramScopes(egoPublicKey)(args.egoJwt); | ||
return (isDccMember(egoPublicKey)(args.egoJwt) || | ||
authorizedProgramScopes.some(function (_a) { | ||
@@ -218,3 +218,3 @@ var policy = _a.policy, permission = _a.permission; | ||
})); | ||
}; | ||
}; }; | ||
/** | ||
@@ -224,5 +224,5 @@ * checks if a given token can read any program at all | ||
*/ | ||
exports.canReadSomeProgram = function (egoJwt) { | ||
return exports.isDccMember(egoJwt) || !!exports.getReadableProgramScopes(egoJwt).length; | ||
}; | ||
var canReadSomeProgram = function (egoPublicKey) { return function (egoJwt) { | ||
return (isDccMember(egoPublicKey)(egoJwt) || !!getReadableProgramScopes(egoPublicKey)(egoJwt).length); | ||
}; }; | ||
/** | ||
@@ -232,5 +232,5 @@ * checks if a given token can write to any program at all | ||
*/ | ||
exports.canWriteSomeProgram = function (egoJwt) { | ||
return exports.isDccMember(egoJwt) || !!exports.getWriteableProgramScopes(egoJwt).length; | ||
}; | ||
var canWriteSomeProgram = function (egoPublicKey) { return function (egoJwt) { | ||
return (isDccMember(egoPublicKey)(egoJwt) || !!getWriteableProgramScopes(egoPublicKey)(egoJwt).length); | ||
}; }; | ||
/** | ||
@@ -240,23 +240,21 @@ * check if a given JWT has admin access to program with given id | ||
*/ | ||
exports.isProgramAdmin = function (args) { | ||
return exports.canWriteProgram(args); | ||
}; | ||
exports.default = { | ||
isPermission: exports.isPermission, | ||
decodeToken: exports.decodeToken, | ||
isValidJwt: exports.isValidJwt, | ||
isDccMember: exports.isDccMember, | ||
isRdpcMember: exports.isRdpcMember, | ||
parseScope: exports.parseScope, | ||
serializeScope: exports.serializeScope, | ||
getReadableProgramScopes: exports.getReadableProgramScopes, | ||
getWriteableProgramScopes: exports.getWriteableProgramScopes, | ||
canReadProgram: exports.canReadProgram, | ||
canWriteProgram: exports.canWriteProgram, | ||
isProgramAdmin: exports.isProgramAdmin, | ||
canReadSomeProgram: exports.canReadSomeProgram, | ||
canWriteSomeProgram: exports.canWriteSomeProgram, | ||
getReadableProgramShortNames: exports.getReadableProgramShortNames, | ||
getWriteableProgramShortNames: exports.getWriteableProgramShortNames | ||
}; | ||
var isProgramAdmin = function (egoPublicKey) { return function (args) { return canWriteProgram(egoPublicKey)(args); }; }; | ||
exports.default = (function (egoPublicKey) { return ({ | ||
serializeScope: serializeScope, | ||
parseScope: parseScope, | ||
isPermission: isPermission, | ||
decodeToken: decodeToken(egoPublicKey), | ||
isValidJwt: isValidJwt(egoPublicKey), | ||
isDccMember: isDccMember(egoPublicKey), | ||
isRdpcMember: isRdpcMember(egoPublicKey), | ||
getReadableProgramScopes: getReadableProgramScopes(egoPublicKey), | ||
getWriteableProgramScopes: getWriteableProgramScopes(egoPublicKey), | ||
canReadProgram: canReadProgram(egoPublicKey), | ||
canWriteProgram: canWriteProgram(egoPublicKey), | ||
isProgramAdmin: isProgramAdmin(egoPublicKey), | ||
canReadSomeProgram: canReadSomeProgram(egoPublicKey), | ||
canWriteSomeProgram: canWriteSomeProgram(egoPublicKey), | ||
getReadableProgramShortNames: getReadableProgramShortNames(egoPublicKey), | ||
getWriteableProgramShortNames: getWriteableProgramShortNames(egoPublicKey) | ||
}); }); | ||
//# sourceMappingURL=ego-token-utils.js.map |
@@ -35,97 +35,5 @@ declare const PERMISSIONS: { | ||
}; | ||
/** | ||
* checks if a string is a proper permission | ||
* @param str | ||
*/ | ||
export declare const isPermission: (str: any) => str is "READ" | "WRITE" | "ADMIN" | "DENY"; | ||
/** | ||
* wrapper for jwt-decode that provides static Ego typing | ||
* @param egoJwt | ||
*/ | ||
export declare const decodeToken: (egoJwt: string) => EgoJwtData; | ||
/** | ||
* checks if a given jwt is valid and has not expired. | ||
* currently does not validate against Ego signature | ||
* @param egoJwt | ||
*/ | ||
export declare const isValidJwt: (egoJwt?: string | undefined) => boolean; | ||
/** | ||
* check if a given jwt has dcc access | ||
* @param egoJwt | ||
*/ | ||
export declare const isDccMember: (egoJwt: string) => boolean; | ||
/** | ||
* check if a given jwt has rdpc access | ||
* @param egoJwt | ||
*/ | ||
export declare const isRdpcMember: (egoJwt: string) => boolean; | ||
/** | ||
* takes a scope string and returns an object for interpretation | ||
* @param scope should be of the format `<policy>.<permission>` | ||
*/ | ||
export declare const parseScope: (scope: string) => PermissionScopeObj; | ||
/** | ||
* takes an PermissionScopeObj and returns a scope string in the format `<policy>.<permission>` | ||
* @param scopeObj | ||
*/ | ||
export declare const serializeScope: (scopeObj: PermissionScopeObj) => string; | ||
/** | ||
* get an array of PermissionScopeObj which gives at least `.READ` permission to the token | ||
* does not return entries that are given `.DENY` | ||
* @param egoJwt | ||
*/ | ||
export declare const getReadableProgramScopes: (egoJwt: string) => PermissionScopeObj[]; | ||
/** | ||
* get an array of PermissionScopeObj which gives at least `.WRITE` permission to the token | ||
* does not return entries that are given `.DENY` | ||
* @param egoJwt | ||
*/ | ||
export declare const getWriteableProgramScopes: (egoJwt: string) => PermissionScopeObj[]; | ||
/** | ||
* get an array of program short names where the user has been given at least `.READ` permission | ||
* in the provided token | ||
* @param egoJwt | ||
*/ | ||
export declare const getReadableProgramShortNames: (egoJwt: string) => string[]; | ||
/** | ||
* get an array of program short names where the user has been given at least `.READ` permission | ||
* in the provided token | ||
* @param egoJwt | ||
*/ | ||
export declare const getWriteableProgramShortNames: (egoJwt: string) => string[]; | ||
/** | ||
* check if a given JWT can read program with given id | ||
* @param args | ||
*/ | ||
export declare const canReadProgram: (args: { | ||
egoJwt: string; | ||
programId: string; | ||
}) => boolean; | ||
/** | ||
* check if a given JWT can write program with given id | ||
* @param args | ||
*/ | ||
export declare const canWriteProgram: (args: { | ||
egoJwt: string; | ||
programId: string; | ||
}) => boolean; | ||
/** | ||
* checks if a given token can read any program at all | ||
* @param egoJwt the ego token | ||
*/ | ||
export declare const canReadSomeProgram: (egoJwt: string) => boolean; | ||
/** | ||
* checks if a given token can write to any program at all | ||
* @param egoJwt the ego token | ||
*/ | ||
export declare const canWriteSomeProgram: (egoJwt: string) => boolean; | ||
/** | ||
* check if a given JWT has admin access to program with given id | ||
* @param args | ||
*/ | ||
export declare const isProgramAdmin: (args: { | ||
egoJwt: string; | ||
programId: string; | ||
}) => boolean; | ||
declare const _default: { | ||
declare const _default: (egoPublicKey: string) => { | ||
serializeScope: (scopeObj: PermissionScopeObj) => string; | ||
parseScope: (scope: string) => PermissionScopeObj; | ||
isPermission: (str: any) => str is "READ" | "WRITE" | "ADMIN" | "DENY"; | ||
@@ -136,4 +44,2 @@ decodeToken: (egoJwt: string) => EgoJwtData; | ||
isRdpcMember: (egoJwt: string) => boolean; | ||
parseScope: (scope: string) => PermissionScopeObj; | ||
serializeScope: (scopeObj: PermissionScopeObj) => string; | ||
getReadableProgramScopes: (egoJwt: string) => PermissionScopeObj[]; | ||
@@ -140,0 +46,0 @@ getWriteableProgramScopes: (egoJwt: string) => PermissionScopeObj[]; |
{ | ||
"name": "@icgc-argo/ego-token-utils", | ||
"version": "3.4.0", | ||
"version": "4.0.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122374
932