Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/lib/sso/sso.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import getPool from "@cocalc/database/pool";6import { COLORS } from "@cocalc/database/settings/get-sso-strategies";7import { ssoDispayedName } from "@cocalc/util/auth";8import { sortBy } from "lodash";9import { SSO } from "./types";1011const SQL_SELECT = `SELECT strategy, info,12COALESCE(info -> 'icon', conf -> 'icon') as icon,13COALESCE(info -> 'display', conf -> 'display') as display,14COALESCE(info -> 'exclusive_domains', conf -> 'exclusive_domains') as exclusive_domains`;1516interface Row {17strategy: string;18display?: string;19exclusive_domains?: string[];20info?: any;21icon?: string;22}2324function parseRow(row: Row): SSO {25const { strategy, exclusive_domains, display, info, icon } = row;26return {27id: strategy,28display: ssoDispayedName({ display, name: strategy }),29domains: exclusive_domains ?? [],30descr: info?.description ?? null,31backgroundColor: COLORS[strategy] ?? "",32icon,33};34}3536export async function getSSO(): Promise<SSO[]> {37const pool = getPool("long");38const { rows } = await pool.query(`39${SQL_SELECT}40FROM passport_settings41WHERE coalesce(info -> 'public', conf -> 'public', 'true'::JSONB)::BOOL IS FALSE`);42const data = rows.map((row) => parseRow(row));43return sortBy(data, (sso) => sso.display);44}4546export async function getOneSSO(id: string): Promise<SSO | undefined> {47const pool = getPool("long");48const { rows } = await pool.query(49`${SQL_SELECT}50FROM passport_settings51WHERE strategy=$1`,52[id]53);54if (rows.length === 0) return;55return parseRow(rows[0]);56}575859