-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.server.ts
33 lines (30 loc) · 963 Bytes
/
utils.server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type {
SAMLSSOConnection,
OIDCSSOConnection,
} from "@boxyhq/saml-jackson";
export function validateEmail(email: string) {
if (
Array.isArray(
String(email)
.toLowerCase()
.match(
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
)
) === false
) {
return "Not a valid email";
}
}
export function validateProduct(product: string) {
const allowedProducts = ["saml-demo.boxyhq.com", "1eef7782-41d4-4a0a-b450-0857413b4f63"];
if (allowedProducts.includes(product) === false) {
return "Not a valid product";
}
}
export const strategyChecker = (
body: SAMLSSOConnection | OIDCSSOConnection
): { isSAML: boolean; isOIDC: boolean } => {
const isSAML = "rawMetadata" in body || "encodedRawMetadata" in body;
const isOIDC = "oidcDiscoveryUrl" in body;
return { isSAML, isOIDC };
};