UNPKG

deep-security

Version:
87 lines (63 loc) 3.78 kB
/** * Created by CCristi on 4/4/17. */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserPoolImplementation = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _awsSdk = require('aws-sdk'); var _awsSdk2 = _interopRequireDefault(_awsSdk); var _AbstractImplementation = require('./AbstractImplementation'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } let UserPoolImplementation = exports.UserPoolImplementation = function (_AbstractImplementati) { _inherits(UserPoolImplementation, _AbstractImplementati); /** * @param {Object[]|*} args */ function UserPoolImplementation() { var _ref; _classCallCheck(this, UserPoolImplementation); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _possibleConstructorReturn(this, (_ref = UserPoolImplementation.__proto__ || Object.getPrototypeOf(UserPoolImplementation)).call.apply(_ref, [this].concat(args))); } /** * @returns {Promise} */ _createClass(UserPoolImplementation, [{ key: 'refreshIdentity', value: function refreshIdentity() { let payload = { AuthFlow: 'REFRESH_TOKEN_AUTH', AuthParameters: { REFRESH_TOKEN: this.refreshToken, ClientId: this.clientName } }; return this.cognitoIdentityServiceProvider.makeUnauthenticatedRequest('initiateAuth', payload).promise().then(response => { let authResult = response.AuthenticationResult; this.identityProvider.tokenExpirationTime = Date.now() + authResult.ExpiresIn * 1000; this.identityProvider.userToken = authResult.IdToken; }); } /** * @returns {AWS.CognitoIdentityServiceProvider} */ }, { key: 'cognitoIdentityServiceProvider', get: function get() { if (_awsSdk2.default.hasOwnProperty('CognitoIdentityServiceProvider')) { // token refresh doesn't need any AWS credentials passed to service config return new _awsSdk2.default.CognitoIdentityServiceProvider(); } throw new Error(`Missing CognitoIdentityServiceProvider in aws-sdk@${_awsSdk2.default.VERSION}`); } }]); return UserPoolImplementation; }(_AbstractImplementation.AbstractImplementation);