-
-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathaws-saml-assertion-extraction-service.ts
More file actions
50 lines (44 loc) · 1.9 KB
/
Copy pathaws-saml-assertion-extraction-service.ts
File metadata and controls
50 lines (44 loc) · 1.9 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { CloudProviderType } from "../models/cloud-provider-type";
import { LoggedException, LogLevel } from "./log-service";
interface ResponseHookDetails {
uploadData: { bytes: any[] }[];
}
const authenticationUrlRegexes = new Map([
[
CloudProviderType.aws,
[
/^https:\/\/.*\.onelogin\.com\/.*/,
/^https:\/\/.*\/adfs\/ls\/idpinitiatedsignon.*loginToRp=urn:amazon:webservices.*/,
/^https:\/\/login\.okta\.com\/.*/,
/^https:\/\/accounts\.google\.com\/ServiceLogin.*/,
/^https:\/\/login\.microsoftonline\.com\/*.*\/oauth2\/authorize.*/,
/^https:\/\/.+\.auth0\.com\/u\/login\/.+/,
/^https:\/\/.*[/auth]?\/realms\/.*\/protocol\/saml\/clients\/.*/,
/^https:\/\/console\.jumpcloud\.com\/login.*/,
/^https:\/\/accounts\.google\.com\/AccountChooser.*/,
/^https:\/\/github\..+\/login\/oauth\/authorize.*/,
],
],
]);
const samlAssertionRegexes = new Map([
[CloudProviderType.aws, [/^https:\/\/signin\.aws\.amazon\.com\/saml/, /^https:\/\/signin\.amazonaws-us-gov\.com\/saml/]],
]);
export class AwsSamlAssertionExtractionService {
isAuthenticationUrl(cloudProvider: CloudProviderType, url: string): boolean {
return authenticationUrlRegexes.get(cloudProvider).some((regex) => regex.test(url));
}
isSamlAssertionUrl(cloudProvider: CloudProviderType, url: string): boolean {
return samlAssertionRegexes.get(cloudProvider).some((regex) => regex.test(url));
}
extractAwsSamlResponse(responseHookDetails: ResponseHookDetails): string {
try {
let rawData = responseHookDetails.uploadData[0].bytes.toString();
const n = rawData.lastIndexOf("SAMLResponse=");
const n2 = rawData.lastIndexOf("&RelayState=");
rawData = n2 !== -1 ? rawData.substring(n + 13, n2) : rawData.substring(n + 13);
return decodeURIComponent(rawData);
} catch (err) {
throw new LoggedException(err.message, this, LogLevel.warn);
}
}
}