@8base/web-auth0-auth-client
Advanced tools
Comparing version 0.11.0 to 0.11.1
@@ -20,4 +20,2 @@ "use strict"; | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -43,2 +41,12 @@ | ||
}); | ||
var prepareState = function prepareState(_ref) { | ||
var workspaceId = _ref.workspaceId, | ||
profileId = _ref.profileId; | ||
var state = JSON.stringify({ | ||
workspaceId: workspaceId, | ||
profileId: profileId | ||
}); | ||
return state === '{}' ? undefined : state; | ||
}; | ||
/** | ||
@@ -52,252 +60,248 @@ * Create instacne of the web auth0 auth client. | ||
var WebAuth0AuthClient = | ||
/*#__PURE__*/ | ||
function () { | ||
function WebAuth0AuthClient(_ref) { | ||
var _this = this; | ||
var domain = _ref.domain, | ||
clientId = _ref.clientId, | ||
redirectUri = _ref.redirectUri, | ||
workspaceId = _ref.workspaceId, | ||
logoutRedirectUri = _ref.logoutRedirectUri; | ||
(0, _classCallCheck2.default)(this, WebAuth0AuthClient); | ||
(0, _defineProperty2.default)(this, "auth0", void 0); | ||
(0, _defineProperty2.default)(this, "workspaceId", void 0); | ||
(0, _defineProperty2.default)(this, "logoutRedirectUri", void 0); | ||
(0, _defineProperty2.default)(this, "authorize", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee() { | ||
var options, | ||
_args = arguments; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
options = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}; | ||
var WebAuth0AuthClient = function WebAuth0AuthClient(_ref2) { | ||
var _this = this; | ||
_this.auth0.authorize((0, _objectSpread2.default)({ | ||
state: _this.getAuthorizeState() | ||
}, options)); | ||
var domain = _ref2.domain, | ||
clientId = _ref2.clientId, | ||
redirectUri = _ref2.redirectUri, | ||
logoutRedirectUri = _ref2.logoutRedirectUri, | ||
workspaceId = _ref2.workspaceId, | ||
profileId = _ref2.profileId; | ||
(0, _classCallCheck2.default)(this, WebAuth0AuthClient); | ||
(0, _defineProperty2.default)(this, "auth0", void 0); | ||
(0, _defineProperty2.default)(this, "logoutRedirectUri", void 0); | ||
(0, _defineProperty2.default)(this, "workspaceId", void 0); | ||
(0, _defineProperty2.default)(this, "profileId", void 0); | ||
(0, _defineProperty2.default)(this, "authorize", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee() { | ||
var options, | ||
_args = arguments; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
options = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}; | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
_this.auth0.authorize((0, _objectSpread2.default)({ | ||
state: prepareState({ | ||
workspaceId: _this.workspaceId, | ||
profileId: _this.profileId | ||
}) | ||
}, options)); | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this); | ||
}))); | ||
(0, _defineProperty2.default)(this, "renewToken", function () { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return new Promise(function (resolve, reject) { | ||
_this.auth0.checkSession(options, function (error, result) { | ||
if (error) { | ||
reject(error || {}); | ||
return; | ||
} | ||
} | ||
}, _callee, this); | ||
}))); | ||
(0, _defineProperty2.default)(this, "renewToken", function () { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return new Promise(function (resolve, reject) { | ||
_this.auth0.checkSession(options, function (error, result) { | ||
if (error) { | ||
reject(error || {}); | ||
return; | ||
} | ||
resolve({ | ||
state: getState(result), | ||
email: getEmail(result), | ||
idToken: getIdToken(result), | ||
isEmailVerified: isEmailVerified(result), | ||
idTokenPayload: getIdTokenPayload(result) | ||
}); | ||
resolve({ | ||
state: getState(result), | ||
email: getEmail(result), | ||
idToken: getIdToken(result), | ||
isEmailVerified: isEmailVerified(result), | ||
idTokenPayload: getIdTokenPayload(result) | ||
}); | ||
}); | ||
}); | ||
(0, _defineProperty2.default)(this, "changePassword", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee2() { | ||
var _ref4, email; | ||
}); | ||
(0, _defineProperty2.default)(this, "changePassword", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee2() { | ||
var _ref5, email; | ||
return _regenerator.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return _this.getAuthState(); | ||
return _regenerator.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return _this.getAuthState(); | ||
case 2: | ||
_ref4 = _context2.sent; | ||
email = _ref4.email; | ||
return _context2.abrupt("return", new Promise(function (resolve, reject) { | ||
_this.auth0.changePassword({ | ||
connection: 'Username-Password-Authentication', | ||
case 2: | ||
_ref5 = _context2.sent; | ||
email = _ref5.email; | ||
return _context2.abrupt("return", new Promise(function (resolve, reject) { | ||
_this.auth0.changePassword({ | ||
connection: 'Username-Password-Authentication', | ||
email: email | ||
}, function (error) { | ||
if (error) { | ||
reject(error || {}); | ||
return; | ||
} | ||
resolve({ | ||
email: email | ||
}, function (error) { | ||
if (error) { | ||
reject(error || {}); | ||
return; | ||
} | ||
resolve({ | ||
email: email | ||
}); | ||
}); | ||
})); | ||
}); | ||
})); | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this); | ||
}))); | ||
(0, _defineProperty2.default)(this, "getAuthorizedData", function () { | ||
return new Promise(function (resolve, reject) { | ||
_this.auth0.parseHash(function (error, authResult) { | ||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
} | ||
}, _callee2, this); | ||
}))); | ||
(0, _defineProperty2.default)(this, "getAuthorizedData", function () { | ||
return new Promise(function (resolve, reject) { | ||
_this.auth0.parseHash(function (error, authResult) { | ||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
resolve({ | ||
state: getState(authResult), | ||
email: getEmail(authResult), | ||
idToken: getIdToken(authResult), | ||
isEmailVerified: isEmailVerified(authResult), | ||
idTokenPayload: getIdTokenPayload(authResult) | ||
}); | ||
resolve({ | ||
state: getState(authResult), | ||
email: getEmail(authResult), | ||
idToken: getIdToken(authResult), | ||
isEmailVerified: isEmailVerified(authResult), | ||
idTokenPayload: getIdTokenPayload(authResult) | ||
}); | ||
}); | ||
}); | ||
(0, _defineProperty2.default)(this, "setAuthState", | ||
}); | ||
(0, _defineProperty2.default)(this, "setAuthState", | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref6 = (0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref5 = (0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee3(state) { | ||
return _regenerator.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
localStorageAccessor.setAuthState(state); | ||
case 1: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, this); | ||
})); | ||
return function (_x) { | ||
return _ref5.apply(this, arguments); | ||
}; | ||
}()); | ||
(0, _defineProperty2.default)(this, "getAuthState", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee4() { | ||
return _regenerator.default.wrap(function _callee4$(_context4) { | ||
_regenerator.default.mark(function _callee3(state) { | ||
return _regenerator.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
return _context4.abrupt("return", localStorageAccessor.getAuthState()); | ||
localStorageAccessor.setAuthState(state); | ||
case 1: | ||
case "end": | ||
return _context4.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee4, this); | ||
}))); | ||
(0, _defineProperty2.default)(this, "purgeAuthState", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee5() { | ||
return _regenerator.default.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
localStorageAccessor.purgeAuthState(); | ||
}, _callee3, this); | ||
})); | ||
case 1: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
return function (_x) { | ||
return _ref6.apply(this, arguments); | ||
}; | ||
}()); | ||
(0, _defineProperty2.default)(this, "getAuthState", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee4() { | ||
return _regenerator.default.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
return _context4.abrupt("return", localStorageAccessor.getAuthState()); | ||
case 1: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
}, _callee5, this); | ||
}))); | ||
(0, _defineProperty2.default)(this, "checkIsAuthorized", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee6() { | ||
var _ref9, token; | ||
} | ||
}, _callee4, this); | ||
}))); | ||
(0, _defineProperty2.default)(this, "purgeAuthState", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee5() { | ||
return _regenerator.default.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
localStorageAccessor.purgeAuthState(); | ||
return _regenerator.default.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
_context6.next = 2; | ||
return _this.getAuthState(); | ||
case 1: | ||
case "end": | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee5, this); | ||
}))); | ||
(0, _defineProperty2.default)(this, "checkIsAuthorized", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee6() { | ||
var _ref10, token; | ||
case 2: | ||
_ref9 = _context6.sent; | ||
token = _ref9.token; | ||
return _context6.abrupt("return", R.not(isEmptyOrNil(token))); | ||
return _regenerator.default.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
_context6.next = 2; | ||
return _this.getAuthState(); | ||
case 5: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
case 2: | ||
_ref10 = _context6.sent; | ||
token = _ref10.token; | ||
return _context6.abrupt("return", R.not(isEmptyOrNil(token))); | ||
case 5: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
}, _callee6, this); | ||
}))); | ||
(0, _defineProperty2.default)(this, "logout", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee7() { | ||
var options, | ||
_args7 = arguments; | ||
return _regenerator.default.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
options = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {}; | ||
} | ||
}, _callee6, this); | ||
}))); | ||
(0, _defineProperty2.default)(this, "logout", | ||
/*#__PURE__*/ | ||
(0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee7() { | ||
var options, | ||
_args7 = arguments; | ||
return _regenerator.default.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
options = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {}; | ||
_this.auth0.logout((0, _objectSpread2.default)({ | ||
returnTo: _this.logoutRedirectUri | ||
}, options)); | ||
_this.auth0.logout((0, _objectSpread2.default)({ | ||
returnTo: _this.logoutRedirectUri | ||
}, options)); | ||
case 2: | ||
case "end": | ||
return _context7.stop(); | ||
} | ||
case 2: | ||
case "end": | ||
return _context7.stop(); | ||
} | ||
}, _callee7, this); | ||
}))); | ||
this.workspaceId = workspaceId; | ||
this.logoutRedirectUri = logoutRedirectUri; | ||
this.auth0 = new _auth0Js.default.WebAuth({ | ||
domain: domain, | ||
clientID: clientId, | ||
redirectUri: redirectUri, | ||
mustAcceptTerms: true, | ||
responseType: 'token id_token', | ||
scope: 'openid email profile', | ||
state: this.getAuthorizeState() | ||
}); | ||
} | ||
} | ||
}, _callee7, this); | ||
}))); | ||
this.logoutRedirectUri = logoutRedirectUri; | ||
this.workspaceId = workspaceId; | ||
this.profileId = profileId; | ||
this.auth0 = new _auth0Js.default.WebAuth({ | ||
domain: domain, | ||
clientID: clientId, | ||
redirectUri: redirectUri, | ||
mustAcceptTerms: true, | ||
responseType: 'token id_token', | ||
scope: 'openid email profile', | ||
state: prepareState({ | ||
workspaceId: workspaceId, | ||
profileId: profileId | ||
}) | ||
}); | ||
}; | ||
(0, _createClass2.default)(WebAuth0AuthClient, [{ | ||
key: "getAuthorizeState", | ||
value: function getAuthorizeState() { | ||
return this.workspaceId ? JSON.stringify({ | ||
workspaceId: this.workspaceId | ||
}) : undefined; | ||
} | ||
}]); | ||
return WebAuth0AuthClient; | ||
}(); | ||
exports.WebAuth0AuthClient = WebAuth0AuthClient; |
{ | ||
"name": "@8base/web-auth0-auth-client", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"author": "8base", | ||
@@ -16,3 +16,3 @@ "repository": "https://github.com/8base/sdk", | ||
"dependencies": { | ||
"@8base/utils": "^0.11.0", | ||
"@8base/utils": "^0.11.1", | ||
"@babel/runtime": "^7.3.1", | ||
@@ -19,0 +19,0 @@ "auth0-js": "^9.9.1", |
Sorry, the diff of this file is not supported yet
301
18951
Updated@8base/utils@^0.11.1