Repository URL to install this package:
|
Version:
0.4.21 ▾
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import React, { Component } from 'react';
import { Route, withRouter } from 'react-router-dom';
import PropTypes from 'prop-types';
import { Auth, ImplicitCallback } from '@okta/okta-react';
import { Login } from '../login';
import AuthManager from './AuthManager';
var Security =
/*#__PURE__*/
function (_Component) {
_inherits(Security, _Component);
function Security(props) {
var _this;
_classCallCheck(this, Security);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Security).call(this, props));
var onAuthRequired = function onAuthRequired(_ref) {
var history = _ref.history;
if (history && history.location && history.location.pathname) {
console.log(history.location.pathname);
localStorage.setItem("secureLoginReferrerPath", history.location.pathname);
}
history.push('/login');
};
_this.auth = new Auth({
history: _this.props.history,
issuer: _this.props.issuerId,
client_id: _this.props.clientId,
clientId: _this.props.clientId,
response_type: ['id_token'],
responseType: ['id_token'],
scopes: ['openid', 'email', 'profile', 'groups'],
redirect_uri: window.location.origin + '/implicit/callback',
onAuthRequired: onAuthRequired
});
_this.authMgr = new AuthManager(_this.auth);
_this.isAuthenticated = _this.isAuthenticated.bind(_assertThisInitialized(_this));
_this.isAuthorizedFor = _this.isAuthorizedFor.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(Security, [{
key: "isAuthenticated",
value: function () {
var _isAuthenticated = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee() {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", this.authMgr.isAuthenticated());
case 1:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
function isAuthenticated() {
return _isAuthenticated.apply(this, arguments);
}
return isAuthenticated;
}()
}, {
key: "isAuthorizedFor",
value: function () {
var _isAuthorizedFor = _asyncToGenerator(
/*#__PURE__*/
_regeneratorRuntime.mark(function _callee2(allowedGroups, path) {
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
return _context2.abrupt("return", this.authMgr.isAuthorizedFor(allowedGroups, path));
case 1:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function isAuthorizedFor(_x, _x2) {
return _isAuthorizedFor.apply(this, arguments);
}
return isAuthorizedFor;
}()
}, {
key: "getChildContext",
value: function getChildContext() {
return {
auth: this.auth,
isAuthenticated: this.isAuthenticated,
isAuthorizedFor: this.isAuthorizedFor
};
}
}, {
key: "render",
value: function render() {
return React.createElement("div", {
className: this.props.className
}, React.createElement(Route, {
path: "/implicit/callback",
exact: true,
component: ImplicitCallback
}), this.props.children, React.createElement(Route, {
path: "/login",
render: function render() {
return React.createElement(Login, {
baseUrl: 'https://barnhardt.okta.com'
});
}
}));
}
}]);
return Security;
}(Component);
Security.childContextTypes = {
auth: PropTypes.object.isRequired,
isAuthenticated: PropTypes.func.isRequired,
isAuthorizedFor: PropTypes.func.isRequired
};
export default withRouter(Security);
//# sourceMappingURL=Security.js.map