Path: blob/master/src/packages/next/pages/sso/index.tsx
5536 views
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Card, Col, Layout, Row, Typography } from "antd";6import Link from "next/link";78import { to_human_list } from "@cocalc/util/misc";9import { StrategyAvatar } from "components/auth/sso";10import Footer from "components/landing/footer";11import Head from "components/landing/head";12import Header from "components/landing/header";13import Main from "components/landing/main";14import { ssoNav } from "components/sso";15import { Customize, CustomizeType } from "lib/customize";16import { getSSO } from "lib/sso/sso";17import { SSO } from "lib/sso/types";18import withCustomize from "lib/with-customize";1920import type { JSX } from "react";2122const { Paragraph, Text } = Typography;2324interface Props {25customize: CustomizeType;26ssos: SSO[];27}2829export const SSO_SUBTITLE = "Single Sign On";3031export default function SignupIndex(props: Props) {32const { customize, ssos } = props;3334function renderDomains(domains) {35if (domains == null || domains.length === 0) return;36const names = (domains ?? []).map((d) => (d === "*" ? "all domains" : d));37return <Text type="secondary">{to_human_list(names)}</Text>;38}3940function extra(sso) {41return <Link href={`/sso/${sso.id}`}>more</Link>;42}4344function renderSSOs() {45return ssos.map((sso: SSO) => {46const strategy = {47name: sso.id,48size: 64,49backgroundColor: "",50icon: sso.icon,51display: sso.display,52} as const;53return (54<Col xs={12} md={6} key={sso.id}>55<Card56size="small"57title={<Text strong>{sso.display}</Text>}58extra={extra(sso)}59>60<Paragraph style={{ textAlign: "center" }}>61<StrategyAvatar strategy={strategy} size={64} />62</Paragraph>63<Paragraph style={{ textAlign: "center", marginBottom: 0 }}>64{renderDomains(sso.domains)}65</Paragraph>66</Card>67</Col>68);69});70}7172function renderSSOList(): JSX.Element {73if (ssos.length === 0) {74return (75<Text italic type="danger">76There are no 3rd party SSO providers available.77</Text>78);79} else {80return (81<Row gutter={[24, 24]} align={"top"} wrap={true}>82{renderSSOs()}83</Row>84);85}86}8788function main() {89return (90<>91<h1>{SSO_SUBTITLE}</h1>92<Paragraph>93Sign up at {customize.siteName} via one of these 3<sup>rd</sup> party94single sign-on mechanisms. You need to have an account at the95respective organization in order to complete the sign-up process.96Usually, this will be the only way you can sign up using your97organization specific email address.98</Paragraph>99<Paragraph>{renderSSOList()}</Paragraph>100</>101);102}103104return (105<Customize value={customize}>106<Head title={SSO_SUBTITLE} />107<Layout style={{ background: "white" }}>108<Header />109<Main nav={ssoNav()}>{main()}</Main>110<Footer />111</Layout>112</Customize>113);114}115116export async function getServerSideProps(context) {117const ssos = await getSSO();118return await withCustomize({ context, props: { ssos } });119}120121122