UNPKG

amps-kerberos-authenticator

Version:
1 lines 2.8 kB
"use strict";var __awaiter=this&&this.__awaiter||function(o,a,c,s){return new(c=c||Promise)(function(t,e){function r(t){try{i(s.next(t))}catch(t){e(t)}}function n(t){try{i(s.throw(t))}catch(t){e(t)}}function i(e){e.done?t(e.value):new c(function(t){t(e.value)}).then(r,n)}i((s=s.apply(o,a||[])).next())})},__generator=this&&this.__generator||function(r,n){var i,o,a,t,c={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;c;)try{if(i=1,o&&(a=2&e[0]?o.return:e[0]?o.throw||((a=o.return)&&a.call(o),0):o.next)&&!(a=a.call(o,e[1])).done)return a;switch(o=0,a&&(e=[2&e[0],a.value]),e[0]){case 0:case 1:a=e;break;case 4:return c.label++,{value:e[1],done:!1};case 5:c.label++,o=e[1],e=[0];continue;case 7:e=c.ops.pop(),c.trys.pop();continue;default:if(!(a=0<(a=c.trys).length&&a[a.length-1])&&(6===e[0]||2===e[0])){c=0;continue}if(3===e[0]&&(!a||e[1]>a[0]&&e[1]<a[3])){c.label=e[1];break}if(6===e[0]&&c.label<a[1]){c.label=a[1],a=e;break}if(a&&c.label<a[2]){c.label=a[2],c.ops.push(e);break}a[2]&&c.ops.pop(),c.trys.pop();continue}e=n.call(r,c)}catch(t){e=[6,t],o=0}finally{i=a=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}};exports.__esModule=!0;var kerberos_1=require("kerberos"),IS_WIN="win32"===process.platform,AMPSKerberosAuthenticator=function(){function t(t){var e=this;this.context=function(){return __awaiter(e,void 0,void 0,function(){var e;return __generator(this,function(t){switch(t.label){case 0:return this.client?[3,2]:(e=this,[4,kerberos_1.initializeClient(this.spn)]);case 1:e.client=t.sent(),t.label=2;case 2:return[2,this.client]}})})},validateSPN(t),this.spn=IS_WIN?t:t.replace(/\//g,"@"),this.client=null}return t.prototype.authenticate=function(t,e){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(t){switch(t.label){case 0:return[4,this.context()];case 1:return[2,t.sent().step("")]}})})},t.prototype.retry=function(e,r){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(t){return[2,this.authenticate(e,r)]})})},t.prototype.completed=function(t,e,r){this.client=null},t}();function validateSPN(t){var e,r="^(\\w+/)((([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\\-]*[a-zA-Z0-9]))(:\\d+)?";if(IS_WIN){r+="(@[\\w\\d]+([\\.\\w\\d]*)?)?$",e="<service>/<host>[:<port>][@REALM]"}else e="<service>/<host>[:<port>]",r+="$";if(!t.match(new RegExp(r)))throw new Error("The specified SPN "+t+" does not match the format "+e)}exports.AMPSKerberosAuthenticator=AMPSKerberosAuthenticator,exports.validateSPN=validateSPN;