@digitalpersona/authentication
Version:
DigitalPersona Authentication API
3 lines (2 loc) • 10.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@digitalpersona/core"),require("@digitalpersona/services"),require("u2f-api")):"function"==typeof define&&define.amd?define(["exports","@digitalpersona/core","@digitalpersona/services","u2f-api"],e):e(((t=t||self).dp=t.dp||{},t.dp.authentication=t.dp.authentication||{}),t.dp.core,t.dp.services,t.u2fApi)}(this,function(t,e,n,r){"use strict";var i,o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function a(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}!function(t){t[t.InitClient=0]="InitClient",t[t.InitServer=1]="InitServer",t[t.ContinueClient=2]="ContinueClient",t[t.ContinueServer=3]="ContinueServer"}(i||(i={}));var u=function(){function t(t){void 0===t&&(t=3),this.serverHandle=0,this.clientHandle=0,this.maxRounds=t}return t.prototype.nextStep=function(){return this.serverHandle?this.clientHandle?!this.clientData&&this.serverData?i.ContinueClient:!this.serverData&&this.clientData?i.ContinueServer:function(){throw new Error("Invalid state")}():i.InitClient:i.InitServer},t.prototype.withClientHandle=function(t){return this.clientHandle=t,this.serverData=null,this},t.prototype.withServerHandle=function(t){return this.serverHandle=t,this.clientData=null,this},t.prototype.withServerData=function(t){if(this.serverData=t,this.clientData=null,!this.serverData)throw new Error("No server data");if(--this.maxRounds,this.maxRounds<=0)throw new Error("Handshake stalled");return this},t.prototype.withClientData=function(t){if(this.clientData=t,this.serverData=null,!this.clientData)throw new Error("No client data");return this},t}(),c=function(){function t(t,e){if(this.authService=t,this.authClient=e,!this.authService)throw new Error("authService")}return t.prototype._authenticate=function(t,r){return function(t,r,o,a){if(r instanceof e.Credential)return t||(t=e.User.Everyone()),(t instanceof e.User?o.Authenticate(t,r):o.Authenticate(new e.Ticket(t),r)).then(function(t){return t.jwt});if(!a)return Promise.reject(new Error("Client"));var c=function(u){switch(u.nextStep()){case i.InitClient:return a.init().then(function(t){return c(u.withClientHandle(t.handle).withClientData(t.data))});case i.InitServer:return(null===t||t instanceof e.User?o.CreateAuthentication(t,r):o.CreateAuthentication(new e.Ticket(t),r)).then(function(t){return c(u.withServerHandle(t))});case i.ContinueClient:return a.continue(u.clientHandle,u.serverData).then(function(t){return c(u.withClientData(t))});case i.ContinueServer:return o.ContinueAuthentication(u.serverHandle,e.Base64Url.fromUtf8(u.clientData)).then(function(t){switch(t.status){case n.AuthenticationStatus.Error:return Promise.reject(new Error("Authentication failed"));case n.AuthenticationStatus.Continue:return c(u.withServerData(t.authData));case n.AuthenticationStatus.Completed:return Promise.resolve(t.jwt);default:throw new Error("Unexpected status")}})}},s=new u;return c(s).catch(function(t){return Promise.reject(t)}).finally(function(){s.clientHandle&&a.term(s.clientHandle),s.serverHandle&&o.DestroyAuthentication(s.serverHandle)})}(t,r,this.authService,this.authClient)},t.prototype._identify=function(t){return this.authService.Identify(t).then(function(t){return t.jwt})},t}();var s,h=function(t){function n(e){return t.call(this,e)||this}return a(n,t),n.prototype.authenticate=function(n,r){return t.prototype._authenticate.call(this,n,new e.Credential(e.Credential.SmartCard,r))},n}(c),l=function(t){function n(e){return t.call(this,e)||this}return a(n,t),n.prototype.authenticate=function(n,r){return t.prototype._authenticate.call(this,n,new e.Credential(e.Credential.ContactlessCard,r))},n.prototype.identify=function(t){return this.authService.Identify(new e.Credential(e.Credential.ContactlessCard,t)).then(function(t){return t.jwt})},n}(c),f=function(t){function n(e){return t.call(this,e)||this}return a(n,t),n.prototype.authenticate=function(n,r){return t.prototype._authenticate.call(this,n,new e.Credential(e.Credential.ProximityCard,r))},n.prototype.identify=function(t){return this.authService.Identify(new e.Credential(e.Credential.ProximityCard,t)).then(function(t){return t.jwt})},n}(c);(s=t.FingerPosition||(t.FingerPosition={}))[s.Unknown=0]="Unknown",s[s.RightThumb=1]="RightThumb",s[s.RightIndex=2]="RightIndex",s[s.RightMiddle=3]="RightMiddle",s[s.RightRing=4]="RightRing",s[s.RightLittle=5]="RightLittle",s[s.LeftThumb=6]="LeftThumb",s[s.LeftIndex=7]="LeftIndex",s[s.LeftMiddle=8]="LeftMiddle",s[s.LeftRing=9]="LeftRing",s[s.LeftLittle=10]="LeftLittle";var p,d=function(){function t(t){this.position=t}return t.fromJson=function(e){return new t(e.position)},t}(),y=function(t){function n(e){return t.call(this,e)||this}return a(n,t),n.prototype.getEnrolledFingers=function(t){return this.authService.GetEnrollmentData(t,e.Credential.Fingerprints).then(function(t){return JSON.parse(e.Utf8.fromBase64Url(t)).map(function(t){return d.fromJson(t)})})},n.prototype.authenticate=function(n,r){return t.prototype._authenticate.call(this,n,new e.Credential(e.Credential.Fingerprints,r))},n.prototype.identify=function(n){return t.prototype._identify.call(this,new e.Credential(e.Credential.Fingerprints,n))},n}(c),C=function(t){function n(e,n){return t.call(this,e,n)||this}return a(n,t),n.prototype.authenticate=function(){return t.prototype._authenticate.call(this,null,e.Credential.IWA)},n}(c),v=function(t){function n(e){return t.call(this,e)||this}return a(n,t),n.prototype.getEnrolledQuestions=function(t){return this.authService.GetEnrollmentData(t,e.Credential.SecurityQuestions).then(function(t){return JSON.parse(e.Utf16.fromBase64Url(t)).map(function(t){return e.Question.fromJson(t)})})},n.prototype.authenticate=function(n,r){return t.prototype._authenticate.call(this,n,new e.Credential(e.Credential.SecurityQuestions,{answers:r}))},n}(c);function w(t){return new e.Credential(e.Credential.OneTimePassword,t)}!function(t){t[t.SendEmailVerificationRequest=16]="SendEmailVerificationRequest",t[t.SendSMSRequest=513]="SendSMSRequest",t[t.SendEmailRequest=514]="SendEmailRequest",t[t.UnlockActiveIdHardwareToken=515]="UnlockActiveIdHardwareToken"}(p||(p={}));var S,m=function(t){function n(e){return t.call(this,e)||this}return a(n,t),n.prototype.authenticate=function(e,n){return t.prototype._authenticate.call(this,e,w(n))},n.prototype.getUnlockCode=function(t,n,r){var i=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}(t instanceof e.User?[t,null]:[e.User.Anonymous(),t],2),o=i[0],a=i[1];return this.authService.CustomAction(p.UnlockActiveIdHardwareToken,new e.Ticket(r||""),o,w({challenge:n,serialNumber:a}))},n}(c),A=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.authenticate=function(e){return t.prototype._authenticate.call(this,e,w("push"))},e}(c),g=function(t){function n(e){return t.call(this,e)||this}return a(n,t),n.prototype.sendChallenge=function(t){return this.authService.CustomAction(p.SendSMSRequest,e.Ticket.None(),t,w()).then()},n.prototype.authenticate=function(e,n){return t.prototype._authenticate.call(this,e,w(n))},n}(c),R=function(t){function n(e){return t.call(this,e)||this}return a(n,t),n.prototype.sendChallenge=function(t){return this.authService.CustomAction(p.SendEmailRequest,e.Ticket.None(),t,w()).then()},n.prototype.authenticate=function(e,n){return t.prototype._authenticate.call(this,e,w(n))},n}(c);function D(t){return new e.Credential(e.Credential.Password,t)}!function(t){t[t.PasswordRandomization=4]="PasswordRandomization",t[t.PasswordReset=13]="PasswordReset"}(S||(S={}));var I,P,_=function(t){function n(e){return t.call(this,e)||this}return a(n,t),n.prototype.authenticate=function(e,n){return t.prototype._authenticate.call(this,e,D(n))},n.prototype.randomize=function(t,n){return this.authService.CustomAction(S.PasswordRandomization,new e.Ticket(n),t,D())},n.prototype.reset=function(t,n,r){return this.authService.CustomAction(S.PasswordReset,new e.Ticket(r),t,D(n)).then()},n}(c),U=function(t){function n(e){return t.call(this,e)||this}return a(n,t),n.prototype.authenticate=function(n,r){return t.prototype._authenticate.call(this,n,new e.Credential(e.Credential.PIN,r))},n}(c),k=function(t){function n(e){return t.call(this,e)||this}return a(n,t),n.prototype.authenticate=function(n,r){return t.prototype._authenticate.call(this,n,new e.Credential(e.Credential.Face,r))},n.prototype.identify=function(n){return t.prototype._identify.call(this,new e.Credential(e.Credential.Face,n))},n}(c);!function(t){t[t.RequestAppId=17]="RequestAppId"}(I||(I={})),function(t){t[t.ChallengeRequest=0]="ChallengeRequest",t[t.ChallengeResponse=1]="ChallengeResponse",t[t.AuthenticationRequest=2]="AuthenticationRequest",t[t.AuthenticationResponse=3]="AuthenticationResponse"}(P||(P={}));var E=function(){return function(){this.handshakeType=0}}(),H=function(){function t(){}return t.prototype.init=function(){var t=new E;return Promise.resolve({handle:1,data:JSON.stringify(t)})},t.prototype.continue=function(t,n){var i=JSON.parse(n);if(1!=i.handshakeType)return Promise.reject(new Error("Unexpected handshake type"));if(!i.handshakeData)return Promise.reject(new Error("No handshake data"));var o=JSON.parse(e.Utf16.fromBase64Url(i.handshakeData));return r.sign(o).then(function(t){var n=JSON.stringify({serialNum:"",version:o.version,appId:o.appId,signatureData:t.signatureData,clientData:t.clientData}),r={handshakeType:2,handshakeData:e.Base64Url.fromUtf16(n)};return JSON.stringify(r)})},t.prototype.term=function(t){return Promise.resolve()},t}(),T=function(t){function n(e){return t.call(this,e,new H)||this}return a(n,t),n.isSupported=function(){return r.isSupported()},n.prototype.getAppId=function(){return this.authService.CustomAction(I.RequestAppId,e.Ticket.None(),e.User.Anonymous(),new e.Credential(e.Credential.U2F,"")).then(function(t){return JSON.parse(t).AppId})},n.prototype.authenticate=function(n){return t.prototype._authenticate.call(this,n,e.Credential.U2F)},n}(c);t.ContactlessCardAuth=l,t.EmailOtpAuth=R,t.FaceAuth=k,t.Finger=d,t.FingerprintsAuth=y,t.PasswordAuth=_,t.PinAuth=U,t.ProximityCardAuth=f,t.PushOtpAuth=A,t.SecurityQuestionsAuth=v,t.SmartCardAuth=h,t.SmsOtpAuth=g,t.TimeOtpAuth=m,t.U2FAuth=T,t.WindowsAuth=C,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=index.umd.min.js.map