CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/database/settings/get-sso-strategies.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import getPool from "@cocalc/database/pool";
7
import type { Strategy } from "@cocalc/util/types/sso";
8
import { ssoDispayedName } from "@cocalc/util/auth";
9
10
/** Returns an array of public info about strategies.
11
* Cached a bit so safe to call a lot.
12
*/
13
export default async function getStrategies(): Promise<Strategy[]> {
14
const pool = getPool("long");
15
// entries in "conf" were used before the "info" col existed. this is only for backwards compatibility.
16
const { rows } = await pool.query(`
17
SELECT strategy,
18
COALESCE(info -> 'icon', conf -> 'icon') as icon,
19
COALESCE(info -> 'display', conf -> 'display') as display,
20
COALESCE(info -> 'public', conf -> 'public') as public,
21
COALESCE(info -> 'exclusive_domains', conf -> 'exclusive_domains') as exclusive_domains,
22
COALESCE(info -> 'do_not_hide', 'false'::JSONB) as do_not_hide
23
24
FROM passport_settings
25
WHERE strategy != 'site_conf'
26
AND COALESCE(info ->> 'disabled', conf ->> 'disabled', 'false') != 'true'`);
27
28
return rows.map((row) => {
29
const display = ssoDispayedName({
30
display: row.display,
31
name: row.strategy,
32
});
33
34
return {
35
name: row.strategy,
36
display,
37
icon: row.icon, // don't use row.strategy as a fallback icon, since that icon likely does not exist
38
backgroundColor: COLORS[row.strategy] ?? "",
39
public: row.public ?? true,
40
exclusiveDomains: row.exclusive_domains ?? [],
41
doNotHide: row.do_not_hide ?? false,
42
};
43
});
44
}
45
46
export const COLORS = {
47
github: "#000000",
48
facebook: "#428bca",
49
google: "#dc4857",
50
twitter: "#55acee",
51
} as const;
52
53