Path: blob/master/src/packages/next/pages/sso/index.tsx
1543 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;36return <Text type="secondary">{to_human_list(domains ?? [])}</Text>;37}3839function extra(sso) {40return <Link href={`/sso/${sso.id}`}>more</Link>;41}4243function renderSSOs() {44return ssos.map((sso: SSO) => {45const strategy = {46name: sso.id,47size: 64,48backgroundColor: "",49icon: sso.icon,50display: sso.display,51} as const;52return (53<Col xs={12} md={6} key={sso.id}>54<Card55size="small"56title={<Text strong>{sso.display}</Text>}57extra={extra(sso)}58>59<Paragraph style={{ textAlign: "center" }}>60<StrategyAvatar strategy={strategy} size={64} />61</Paragraph>62<Paragraph style={{ textAlign: "center", marginBottom: 0 }}>63{renderDomains(sso.domains)}64</Paragraph>65</Card>66</Col>67);68});69}7071function renderSSOList(): JSX.Element {72if (ssos.length === 0) {73return (74<Text italic type="danger">75There are no 3rd party SSO providers available.76</Text>77);78} else {79return (80<Row gutter={[24, 24]} align={"top"} wrap={true}>81{renderSSOs()}82</Row>83);84}85}8687function main() {88return (89<>90<h1>{SSO_SUBTITLE}</h1>91<Paragraph>92Sign up at {customize.siteName} via one of these 3<sup>rd</sup> party93single sign-on mechanisms. You need to have an account at the94respective organization in order to complete the sign-up process.95Usually, this will be the only way you can sign up using your96organization specific email address.97</Paragraph>98<Paragraph>{renderSSOList()}</Paragraph>99</>100);101}102103return (104<Customize value={customize}>105<Head title={SSO_SUBTITLE} />106<Layout style={{ background: "white" }}>107<Header />108<Main nav={ssoNav()}>{main()}</Main>109<Footer />110</Layout>111</Customize>112);113}114115export async function getServerSideProps(context) {116const ssos = await getSSO();117return await withCustomize({ context, props: { ssos } });118}119120121