exports.id = 6009;
exports.ids = [6009];
exports.modules = {

/***/ 121469:
/***/ ((module) => {

// Exports
module.exports = {
	"icon": "sso_icon__bBVcD"
};


/***/ }),

/***/ 366009:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Ke": () => (/* binding */ useRequiredSSO),
/* harmony export */   "Ug": () => (/* binding */ RequiredSSO),
/* harmony export */   "ZP": () => (/* binding */ SSO),
/* harmony export */   "xq": () => (/* binding */ StrategyAvatar)
/* harmony export */ });
/* unused harmony export getLink */
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(920997);
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(807772);
/* harmony import */ var _cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _cocalc_server_auth_sso_check_required_sso__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(347264);
/* harmony import */ var _cocalc_server_auth_sso_check_required_sso__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_cocalc_server_auth_sso_check_required_sso__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _cocalc_util_types_passport_types__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(992326);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(545725);
/* harmony import */ var antd__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(antd__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var components_share_loading__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(976087);
/* harmony import */ var lib_base_path__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(348397);
/* harmony import */ var lib_customize__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(400054);
/* harmony import */ var next_router__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(371853);
/* harmony import */ var next_router__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(next_router__WEBPACK_IMPORTED_MODULE_7__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(371017);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(616689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_9__);
/* harmony import */ var _sso_module_css__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(121469);
/* harmony import */ var _sso_module_css__WEBPACK_IMPORTED_MODULE_11___default = /*#__PURE__*/__webpack_require__.n(_sso_module_css__WEBPACK_IMPORTED_MODULE_11__);
/*
 *  This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */ 










const { Link: AntdLink  } = antd__WEBPACK_IMPORTED_MODULE_4__.Typography;

function getLink(strategy, target) {
    // special case: private SSO mechanism, we point to the overview page
    if (strategy === "sso") {
        return `${(0,path__WEBPACK_IMPORTED_MODULE_8__.join)(lib_base_path__WEBPACK_IMPORTED_MODULE_10__/* ["default"] */ .Z, "sso")}`;
    }
    // TODO: the target is ignored by the server right now -- it's not implemented
    // and I don't know how... yet.  Code is currently in src/packages/hub/auth.ts
    return `${(0,path__WEBPACK_IMPORTED_MODULE_8__.join)(lib_base_path__WEBPACK_IMPORTED_MODULE_10__/* ["default"] */ .Z, "auth", strategy)}${target ? "?target=" + encodeURIComponent(target) : ""}`;
}
function SSO(props) {
    const { size , style , header  } = props;
    const { strategies  } = (0,lib_customize__WEBPACK_IMPORTED_MODULE_6__/* .useCustomize */ .i)();
    const havePrivateSSO = (0,react__WEBPACK_IMPORTED_MODULE_9__.useMemo)(()=>{
        return strategies?.some((s)=>!s.public) ?? false;
    }, [
        strategies
    ]);
    if (strategies == null) {
        return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(components_share_loading__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
            style: {
                fontSize: "16pt"
            }
        });
    }
    if (strategies.length == 0) return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {});
    function renderPrivateSSO() {
        if (!havePrivateSSO) return;
        // a fake entry to point the user to the page for private SSO login options
        const sso = {
            name: "sso",
            display: "institutional Single-Sign-On",
            icon: "api",
            backgroundColor: "",
            public: true,
            exclusiveDomains: [],
            doNotHide: true
        };
        return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
            children: [
                "Institutional Single-Sign-On: ",
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(StrategyAvatar, {
                    strategy: sso,
                    size: size ?? 60
                }, "sso")
            ]
        });
    }
    function renderStrategies() {
        if (strategies == null) return;
        return strategies.filter((s)=>s.public || s.doNotHide).map((strategy)=>/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(StrategyAvatar, {
                strategy: strategy,
                size: size ?? 60
            }, strategy.name));
    }
    // The -5px is to offset the initial avatar image, since they
    // all have a left margin.
    return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
        style: {
            ...style
        },
        children: [
            header,
            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                style: {
                    marginLeft: "-5px"
                },
                children: renderStrategies()
            }),
            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                style: {
                    marginLeft: "-5px",
                    marginTop: "10px"
                },
                children: renderPrivateSSO()
            })
        ]
    });
};
function useSSOHref(name) {
    const router = (0,next_router__WEBPACK_IMPORTED_MODULE_7__.useRouter)();
    if (name == null) return "";
    return getLink(name, (0,path__WEBPACK_IMPORTED_MODULE_8__.join)(router.basePath, router.pathname));
}
function StrategyAvatar(props) {
    const { strategy , size , noLink , toolTip , showName =false  } = props;
    const { name , display , backgroundColor  } = strategy;
    const icon = iconName();
    const ssoHREF = useSSOHref(name);
    const STYLE = {
        fontSize: `${size - 2}px`,
        color: backgroundColor ? "white" : "black",
        margin: "0 2px"
    };
    // this derives the name of the icon, that's shown on the avatar
    // in particular, the old public SSO mechanisms are special cases.
    function iconName() {
        // icon could be "null"
        if (strategy.icon != null) return strategy.icon;
        if (_cocalc_util_types_passport_types__WEBPACK_IMPORTED_MODULE_3__/* .PRIMARY_SSO.includes */ .l.includes(strategy.name)) {
            return strategy.name;
        }
        return "link"; // a chain link, very general fallback
    }
    function renderIconImg() {
        if (icon?.includes("://")) {
            return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("img", {
                src: icon,
                style: {
                    height: `${size - 2}px`,
                    width: `${size - 2}px`,
                    marginLeft: "2.5px",
                    objectFit: "contain"
                }
            });
        } else {
            return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_1__.Icon, {
                name: icon,
                style: {
                    ...STYLE,
                    backgroundColor
                }
            });
        }
    }
    function renderAvatar() {
        const avatar = /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_4__.Avatar, {
            shape: "square",
            size: size,
            src: renderIconImg(),
            gap: 1,
            className: (_sso_module_css__WEBPACK_IMPORTED_MODULE_11___default().icon)
        });
        if (noLink) {
            return avatar;
        } else {
            return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("a", {
                href: ssoHREF,
                children: avatar
            });
        }
    }
    function renderIcon() {
        if (icon?.includes("://")) return "";
        return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_cocalc_frontend_components_icon__WEBPACK_IMPORTED_MODULE_1__.Icon, {
            name: icon,
            style: {
                fontSize: "14pt",
                marginRight: "10px"
            }
        });
    }
    function renderName() {
        if (!showName) return;
        return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
            style: {
                textAlign: "center",
                whiteSpace: "nowrap"
            },
            children: display
        });
    }
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_4__.Tooltip, {
        title: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
            children: [
                renderIcon(),
                " ",
                toolTip ?? /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
                    children: [
                        "Use your ",
                        display,
                        " account."
                    ]
                })
            ]
        }),
        color: backgroundColor,
        children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
            style: {
                display: "inline-block"
            },
            children: [
                renderAvatar(),
                renderName()
            ]
        })
    });
}
function RequiredSSO({ strategy  }) {
    if (strategy == null) return null;
    if (strategy.name == "null") return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_4__.Alert, {
        type: "error",
        message: "SSO Strategy not defined!"
    });
    const ssoLink = (0,path__WEBPACK_IMPORTED_MODULE_8__.join)(lib_base_path__WEBPACK_IMPORTED_MODULE_10__/* ["default"] */ .Z, "sso", strategy.name);
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(antd__WEBPACK_IMPORTED_MODULE_4__.Alert, {
        style: {
            margin: "15px 0"
        },
        type: "warning",
        showIcon: false,
        message: `Single-Sign-On required`,
        description: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
            children: [
                /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("p", {
                    children: [
                        "You must sign up using the",
                        " ",
                        /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(AntdLink, {
                            strong: true,
                            underline: true,
                            href: ssoLink,
                            children: strategy.display
                        }),
                        " ",
                        "Single-Sign-On strategy."
                    ]
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
                    style: {
                        textAlign: "center"
                    },
                    children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(StrategyAvatar, {
                        strategy: strategy,
                        size: 120
                    }, strategy.name)
                })
            ]
        })
    });
}
// based on (partially) entered email address.
// if user has to sign up via SSO, this will tell which strategy to use.
// this also checks for subdomains via a simple heuristic – the precise test is on the backend.
// hence this should be good enough to catch @email.foo.edu for foo.edu domains
function useRequiredSSO(strategies, email) {
    return (0,react__WEBPACK_IMPORTED_MODULE_9__.useMemo)(()=>{
        return (0,_cocalc_server_auth_sso_check_required_sso__WEBPACK_IMPORTED_MODULE_2__.checkRequiredSSO)({
            email,
            strategies
        });
    }, [
        strategies == null,
        email
    ]);
}


/***/ }),

/***/ 992326:
/***/ ((__unused_webpack_module, exports) => {

"use strict";
var __webpack_unused_export__;

__webpack_unused_export__ = ({ value: true });
exports.l = void 0;
exports.l = ["google", "facebook", "github", "twitter"];
//# sourceMappingURL=passport-types.js.map

/***/ })

};
;