@deephaven/auth-plugins
Version:
Deephaven Auth Plugins
56 lines (55 loc) • 2.41 kB
JavaScript
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
import React from 'react';
import { LOGIN_OPTIONS_REQUEST } from '@deephaven/jsapi-utils';
import Log from '@deephaven/log';
import { getWindowParent, requestParentResponse } from '@deephaven/utils';
import AuthPluginBase from "./AuthPluginBase.js";
import { UserPermissionsOverrideContext } from "./UserContexts.js";
import { jsx as _jsx } from "react/jsx-runtime";
var log = Log.module('AuthPluginParent');
var permissionsOverrides = {
canLogout: false
};
function isLoginOptions(options) {
return options != null && typeof options.type === 'string';
}
function getLoginOptions() {
return _getLoginOptions.apply(this, arguments);
}
function _getLoginOptions() {
_getLoginOptions = _asyncToGenerator(function* () {
log.info('Logging in by delegating to parent window...');
var response = yield requestParentResponse(LOGIN_OPTIONS_REQUEST);
if (!isLoginOptions(response)) {
throw new Error("Unexpected login options response: ".concat(response));
}
return response;
});
return _getLoginOptions.apply(this, arguments);
}
function getWindowAuthProvider() {
var _URLSearchParams$get;
return (_URLSearchParams$get = new URLSearchParams(window.location.search).get('authProvider')) !== null && _URLSearchParams$get !== void 0 ? _URLSearchParams$get : '';
}
/**
* AuthPlugin that tries to delegate to the parent window for authentication. Fails if there is no parent window.
*/
function Component(_ref) {
var {
children
} = _ref;
return /*#__PURE__*/_jsx(AuthPluginBase, {
getLoginOptions: getLoginOptions,
children: /*#__PURE__*/_jsx(UserPermissionsOverrideContext.Provider, {
value: permissionsOverrides,
children: children
})
});
}
var AuthPluginParent = {
Component,
isAvailable: () => getWindowParent() != null && getWindowAuthProvider() === 'parent'
};
export default AuthPluginParent;
//# sourceMappingURL=AuthPluginParent.js.map