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