UNPKG

@orcden/od-authentication

Version:

OrcDen Authentication Library

1 lines 16.6 kB
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports["od-authentication"]=r():e["od-authentication"]=r()}(window,(function(){return(()=>{"use strict";var e={371:(e,r,t)=>{t.r(r),t.d(r,{ODCognitoAuth:()=>h,ODCognitoAdmin:()=>v});var n=t(84),s=t.n(n),a=t(406),i=(t(835),t(966)),o=t.n(i);function u(e,r,t,n,s,a,i){try{var o=e[a](i),u=o.value}catch(e){return void t(e)}o.done?r(u):Promise.resolve(u).then(n,s)}function c(e){return function(){var r=this,t=arguments;return new Promise((function(n,s){var a=e.apply(r,t);function i(e){u(a,n,s,i,o,"next",e)}function o(e){u(a,n,s,i,o,"throw",e)}i(void 0)}))}}function l(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var h=function(){function e(r){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this._user=null,this._REGION=r.region,this._USER_POOL_ID=r.userPoolId,this._IDENTITY_POOL_ID=r.identityPoolId,s().configure({Auth:{identityPoolId:this._IDENTITY_POOL_ID,region:this._REGION,identityPoolRegion:r.identityPoolRegion,userPoolId:this._USER_POOL_ID,userPoolWebClientId:r.userPoolWebClientId,authenticationFlowType:r.authenticationFlowType,oauth:{domain:r.oauth.domain,scope:r.oauth.scope,redirectSignIn:r.oauth.redirectSignIn,redirectSignOut:r.oauth.redirectSignOut,responseType:r.oauth.responseType}}})}var r,t,n,a,i,u,h,p,d,m,f,g,v,y,w,b;return r=e,(t=[{key:"tryGetCurrentAuthenticatedUser",value:(b=c(regeneratorRuntime.mark((function e(r){var t,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=!1,n=null,e.prev=2,e.next=5,o().currentAuthenticatedUser({bypassCache:!1});case 5:this._user=e.sent,t=!0,e.next=13;break;case 9:e.prev=9,e.t0=e.catch(2),console.log("No currently logged in user: ",e.t0),n=e.t0;case 13:return r&&r(t,this.user,n),e.abrupt("return",this.user);case 15:case"end":return e.stop()}}),e,this,[[2,9]])}))),function(e){return b.apply(this,arguments)})},{key:"tryGetCurrenSessionData",value:(w=c(regeneratorRuntime.mark((function e(r){var t,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=null,n=null,e.prev=2,e.next=5,o().currentSession();case 5:n=e.sent,e.next=12;break;case 8:e.prev=8,e.t0=e.catch(2),console.log("There was an error while trying to retrieve the current session data: ",e.t0),t=e.t0;case 12:return r&&r(n,t),e.abrupt("return",n);case 14:case"end":return e.stop()}}),e,null,[[2,8]])}))),function(e){return w.apply(this,arguments)})},{key:"trySignUp",value:(y=c(regeneratorRuntime.mark((function e(r,t,n,s){var a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=null,e.prev=1,e.next=4,o().signUp({username:r,password:n,attributes:{email:t}});case 4:this._user=e.sent,e.next=11;break;case 7:e.prev=7,e.t0=e.catch(1),a=e.t0,console.log("There was an error while trying to sign up:",e.t0);case 11:return s&&s(this.user,a),e.abrupt("return",this.user);case 13:case"end":return e.stop()}}),e,this,[[1,7]])}))),function(e,r,t,n){return y.apply(this,arguments)})},{key:"trySignIn",value:(v=c(regeneratorRuntime.mark((function e(r,t,n){var s,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return s=null,a=null,e.prev=2,e.next=5,o().signIn(r,t);case 5:this._user=e.sent,this.user.challengeName&&(s=this.user.challengeName),e.next=13;break;case 9:e.prev=9,e.t0=e.catch(2),a=e.t0,console.log("There was an error while trying to sign in",e.t0);case 13:return n&&n(this.user,s,a),e.abrupt("return",this.user);case 15:case"end":return e.stop()}}),e,this,[[2,9]])}))),function(e,r,t){return v.apply(this,arguments)})},{key:"tryforgotPasswordSendCode",value:(g=c(regeneratorRuntime.mark((function e(r,t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.prev=1,e.next=4,o().forgotPassword(r);case 4:e.next=10;break;case 6:e.prev=6,e.t0=e.catch(1),n=e.t0,console.log(e.t0);case 10:t&&t(n);case 11:case"end":return e.stop()}}),e,null,[[1,6]])}))),function(e,r){return g.apply(this,arguments)})},{key:"tryResendConfirmationCode",value:(f=c(regeneratorRuntime.mark((function e(r,t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.prev=1,e.next=4,o().resendSignUp(r);case 4:e.next=10;break;case 6:e.prev=6,e.t0=e.catch(1),n=e.t0,console.log("There was an error while trying to resend code: ",e.t0);case 10:t&&t(n);case 11:case"end":return e.stop()}}),e,null,[[1,6]])}))),function(e,r){return f.apply(this,arguments)})},{key:"tryforgotPasswordSubmit",value:(m=c(regeneratorRuntime.mark((function e(r,t,n,s){var a,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=null,i=null,e.prev=2,e.next=5,o().forgotPasswordSubmit(r,t,n);case 5:a=e.sent,e.next=12;break;case 8:e.prev=8,e.t0=e.catch(2),console.log("There was an error while trying to confirm new password: ",e.t0),i=e.t0;case 12:return s&&s(a,i),e.abrupt("return",a);case 14:case"end":return e.stop()}}),e,null,[[2,8]])}))),function(e,r,t,n){return m.apply(this,arguments)})},{key:"tryChangePassword",value:(d=c(regeneratorRuntime.mark((function e(r,t,n){var s,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return s=null,a=null,e.prev=2,e.next=5,o().changePassword(this.user,r,t);case 5:s=e.sent,e.next=12;break;case 8:e.prev=8,e.t0=e.catch(2),a=e.t0,console.log("There was an error while trying to change password: ",e.t0);case 12:return n&&n(s,a),e.abrupt("return",s);case 14:case"end":return e.stop()}}),e,this,[[2,8]])}))),function(e,r,t){return d.apply(this,arguments)})},{key:"tryCompleteNewPassword",value:(p=c(regeneratorRuntime.mark((function e(r,t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.prev=1,e.next=4,o().completeNewPassword(this.user,r);case 4:this._user=e.sent,e.next=11;break;case 7:e.prev=7,e.t0=e.catch(1),console.log("There was an error while trying to complete new password"),n=e.t0;case 11:return t&&t(this.user,n),e.abrupt("return",this.user);case 13:case"end":return e.stop()}}),e,this,[[1,7]])}))),function(e,r){return p.apply(this,arguments)})},{key:"trySignOut",value:(h=c(regeneratorRuntime.mark((function e(r){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=null,e.prev=1,e.next=4,o().signOut();case 4:e.next=10;break;case 6:e.prev=6,e.t0=e.catch(1),t=e.t0,console.log("There was an error while trying to sign out: ",e.t0);case 10:r&&r(t);case 11:case"end":return e.stop()}}),e,null,[[1,6]])}))),function(e){return h.apply(this,arguments)})},{key:"tryVerifyEmailSendCode",value:(u=c(regeneratorRuntime.mark((function e(r){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=null;try{o().verifyCurrentUserAttribute("email")}catch(e){console.log("There was an error while trying to send the email verification code: ",e),t=e}r&&r(t);case 3:case"end":return e.stop()}}),e)}))),function(e){return u.apply(this,arguments)})},{key:"tryVerifyEmailSubmit",value:(i=c(regeneratorRuntime.mark((function e(r,t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=null;try{o().verifyCurrentUserAttributeSubmit("email",r)}catch(e){console.log("There was an error while trying to verify email: ",e),n=e}t&&t(n);case 3:case"end":return e.stop()}}),e)}))),function(e,r){return i.apply(this,arguments)})},{key:"tryUpdateEmailSendCode",value:(a=c(regeneratorRuntime.mark((function e(r,t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=null,e.prev=1,e.next=4,o().updateUserAttributes(this.user,{email:r});case 4:e.next=10;break;case 6:e.prev=6,e.t0=e.catch(1),console.log("There was an error while trying to send update email code: ",e.t0),n=e.t0;case 10:t&&t(n);case 11:case"end":return e.stop()}}),e,this,[[1,6]])}))),function(e,r){return a.apply(this,arguments)})},{key:"user",get:function(){return this._user}}])&&l(r.prototype,t),n&&l(r,n),e}(),p=t(335),d=t(540);function m(e,r,t,n,s,a,i){try{var o=e[a](i),u=o.value}catch(e){return void t(e)}o.done?r(u):Promise.resolve(u).then(n,s)}function f(e){return function(){var r=this,t=arguments;return new Promise((function(n,s){var a=e.apply(r,t);function i(e){m(a,n,s,i,o,"next",e)}function o(e){m(a,n,s,i,o,"throw",e)}i(void 0)}))}}function g(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var v=function(){function e(r,t){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this._user=null,this._REGION=r.region,this._USER_POOL_ID=r.userPoolId,this._IDENTITY_POOL_ID=r.identityPoolId,this._cognitoAuth=t}var r,t,n,s,i,o,u,c,l,h;return r=e,(t=[{key:"_createCognitoIdentityProviderClient",value:function(){var e={};return e["cognito-idp."+this._REGION+".amazonaws.com/"+this._USER_POOL_ID]=this.user.signInUserSession.idToken.getJwtToken(),new a.CognitoIdentityProviderClient({region:this._REGION,credentials:(0,d.fromCognitoIdentityPool)({client:new p.CognitoIdentityClient({region:this._REGION}),identityPoolId:this._IDENTITY_POOL_ID,logins:e})})}},{key:"adminCreateUser",value:(h=f(regeneratorRuntime.mark((function e(r,t,n){var s,i,o,u,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.user&&this.user.signInUserSession){e.next=2;break}return e.abrupt("return",n(null,"ERROR: No Authenticated User"));case 2:return s=this._createCognitoIdentityProviderClient(),i={UserPoolId:this._USER_POOL_ID,Username:r,UserAttributes:[{Name:"email",Value:t},{Name:"email_verified",Value:"true"}]},o=new a.AdminCreateUserCommand(i),u=null,c=null,e.prev=7,e.next=10,s.send(o);case 10:c=e.sent,e.next=17;break;case 13:e.prev=13,e.t0=e.catch(7),console.log("There was an error while trying to create the user: ",e.t0),u=e.t0;case 17:return n&&n(c,u),e.abrupt("return",c);case 19:case"end":return e.stop()}}),e,this,[[7,13]])}))),function(e,r,t){return h.apply(this,arguments)})},{key:"adminListUsers",value:(l=f(regeneratorRuntime.mark((function e(r,t,n){var s,i,o,u,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.user&&this.user.signInUserSession){e.next=2;break}return e.abrupt("return",n(null,"ERROR: No Authenticated User"));case 2:return s=this._createCognitoIdentityProviderClient(),i={UserPoolId:this._USER_POOL_ID},r&&(i.Filter=r),t&&(i.PaginationToken=t),o=new a.ListUsersCommand(i),u=null,c=null,e.prev=9,e.next=12,s.send(o);case 12:c=e.sent,e.next=19;break;case 15:e.prev=15,e.t0=e.catch(9),console.log("There was an error while trying to list all user pool users: ",e.t0),u=e.t0;case 19:return n&&n(c.Users,u),e.abrupt("return",c.Users);case 21:case"end":return e.stop()}}),e,this,[[9,15]])}))),function(e,r,t){return l.apply(this,arguments)})},{key:"adminGetUser",value:(c=f(regeneratorRuntime.mark((function e(r,t){var n,s,i,o,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.user&&this.user.signInUserSession){e.next=2;break}return e.abrupt("return",t(null,"ERROR: No Authenticated User"));case 2:return n=this._createCognitoIdentityProviderClient(),s={UserPoolId:this._USER_POOL_ID,Username:r},i=new a.AdminGetUserCommand(s),o=null,u=null,e.prev=7,e.next=10,n.send(i);case 10:u=e.sent,e.next=17;break;case 13:e.prev=13,e.t0=e.catch(7),console.log("There was an error while trying to get the user: ",e.t0),o=e.t0;case 17:return t&&t(u,o),e.abrupt("return",u);case 19:case"end":return e.stop()}}),e,this,[[7,13]])}))),function(e,r){return c.apply(this,arguments)})},{key:"adminGetUserByEmail",value:(u=f(regeneratorRuntime.mark((function e(r,t){var n,s,i,o,u,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.user&&this.user.signInUserSession){e.next=2;break}return e.abrupt("return",t(null,"ERROR: No Authenticated User"));case 2:return n=this._createCognitoIdentityProviderClient(),s={UserPoolId:this._USER_POOL_ID,Filter:'email = "'+r+'"'},i=new a.ListUsersCommand(s),o=null,u=null,e.prev=7,e.next=10,n.send(i);case 10:u=e.sent,e.next=17;break;case 13:e.prev=13,e.t0=e.catch(7),console.log("There was an error while trying to get the user: ",e.t0),o=e.t0;case 17:return c=null,u.Users&&u.Users.length&&u.Users.length>0&&(u.Users.length>1?o="Multiple users found with the same email.":c=u.Users[0]),t&&t(c,o),e.abrupt("return",c);case 21:case"end":return e.stop()}}),e,this,[[7,13]])}))),function(e,r){return u.apply(this,arguments)})},{key:"adminDeleteUser",value:(o=f(regeneratorRuntime.mark((function e(r,t){var n,s,i,o,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.user&&this.user.signInUserSession){e.next=2;break}return e.abrupt("return",t(null,"ERROR: No Authenticated User"));case 2:return n=this._createCognitoIdentityProviderClient(),s={UserPoolId:this._USER_POOL_ID,Username:r},i=new a.AdminDeleteUserCommand(s),o=null,u=null,e.prev=7,e.next=10,n.send(i);case 10:u=e.sent,e.next=17;break;case 13:e.prev=13,e.t0=e.catch(7),console.log("There was an error while trying to delete the user: ",e.t0),o=e.t0;case 17:return t&&t(u,o),e.abrupt("return",u);case 19:case"end":return e.stop()}}),e,this,[[7,13]])}))),function(e,r){return o.apply(this,arguments)})},{key:"adminUpdateUserEmail",value:(i=f(regeneratorRuntime.mark((function e(r,t,n){var s,i,o,u,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.user&&this.user.signInUserSession){e.next=2;break}return e.abrupt("return",n(null,"ERROR: No Authenticated User"));case 2:return s=this._createCognitoIdentityProviderClient(),i={UserPoolId:this._USER_POOL_ID,Username:r,UserAttributes:[{Name:"email",Value:t},{Name:"email_verified",Value:"true"}]},o=new a.AdminUpdateUserAttributesCommand(i),u=null,c=null,e.prev=7,e.next=10,s.send(o);case 10:c=e.sent,e.next=17;break;case 13:e.prev=13,e.t0=e.catch(7),console.log("There was an error while trying to update the users email: ",e.t0),u=e.t0;case 17:return n&&n(c,u),e.abrupt("return",c);case 19:case"end":return e.stop()}}),e,this,[[7,13]])}))),function(e,r,t){return i.apply(this,arguments)})},{key:"adminResendInvites",value:(s=f(regeneratorRuntime.mark((function e(r,t,n,s){var i,o,u,c,l;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.user&&this.user.signInUserSession){e.next=2;break}return e.abrupt("return",s(null,"ERROR: No Authenticated User"));case 2:return i=this._createCognitoIdentityProviderClient(),o={UserPoolId:this._USER_POOL_ID,Username:r},u=new a.AdminDeleteUserCommand(o),c=null,l=null,e.prev=7,e.next=10,i.send(u);case 10:l=e.sent,e.next=18;break;case 13:return e.prev=13,e.t0=e.catch(7),console.log("There was an error while trying to resend the invite emails: ",e.t0),c=e.t0,e.abrupt("return");case 18:return o={UserPoolId:this._USER_POOL_ID,Username:t,UserAttributes:[{Name:"email",Value:n},{Name:"email_verified",Value:"true"}]},u=new a.AdminCreateUserCommand(o),c=null,l=null,e.prev=22,e.next=25,i.send(u);case 25:l=e.sent,e.next=32;break;case 28:e.prev=28,e.t1=e.catch(22),console.log("There was an error while trying to resend the invite emails: ",e.t1),c=e.t1;case 32:return s&&s(l,c),e.abrupt("return",l);case 34:case"end":return e.stop()}}),e,this,[[7,13],[22,28]])}))),function(e,r,t,n){return s.apply(this,arguments)})},{key:"user",get:function(){return this._cognitoAuth.user}}])&&g(r.prototype,t),n&&g(r,n),e}()},966:e=>{e.exports=require("@aws-amplify/auth")},84:e=>{e.exports=require("@aws-amplify/core")},335:e=>{e.exports=require("@aws-sdk/client-cognito-identity")},406:e=>{e.exports=require("@aws-sdk/client-cognito-identity-provider")},540:e=>{e.exports=require("@aws-sdk/credential-provider-cognito-identity")},835:e=>{e.exports=require("regenerator-runtime/runtime")}},r={};function t(n){if(r[n])return r[n].exports;var s=r[n]={exports:{}};return e[n](s,s.exports,t),s.exports}return t.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return t.d(r,{a:r}),r},t.d=(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t(371)})()}));