-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c422a06
commit d350fcb
Showing
17 changed files
with
234 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// import { Authentication, AuthType } from "../../utils/types"; | ||
// import { getAuthType } from "./authentication"; | ||
|
||
// /** | ||
// * Helpers and utilities for endpoint Authentication details | ||
// * Modelled on a Security Scheme Object https://spec.openapis.org/oas/v3.1.0#security-scheme-object | ||
// */ | ||
// export interface APIKeyAuth extends Authentication { | ||
// type: "apiKey"; | ||
// name: string; | ||
// } | ||
|
||
// export interface APIKeyAuthHeader extends APIKeyAuth { | ||
// in: "header"; | ||
// } | ||
|
||
// export type APIKeyAuthHeaders = APIKeyAuthHeader | undefined; | ||
|
||
// export const parseAPIKeyAuthHeader = ( | ||
// header: chrome.devtools.network.Request["request"]["headers"][0] | ||
// ): APIKeyAuthHeaders => { | ||
// const authType = getAuthType(header.value); | ||
// if (authType === "basic") { | ||
// const basicAuth: BasicAuthHeader = { | ||
// id: AuthType.BASIC, | ||
// type: "http", | ||
// in: "header", | ||
// scheme: "Basic", | ||
// description: "", | ||
// }; | ||
// return basicAuth; | ||
// } else if (authType === "bearer") { | ||
// const bearerAuth: BearerAuthHeader = { | ||
// id: AuthType.BEARER, | ||
// type: "http", | ||
// in: "header", | ||
// scheme: "Bearer", | ||
// description: "", | ||
// }; | ||
// return bearerAuth; | ||
// } else if (authType === "digest") { | ||
// const digestAuth: DigestAuthHeader = { | ||
// id: AuthType.DIGEST, | ||
// type: "http", | ||
// in: "header", | ||
// scheme: "Digest", | ||
// description: "", | ||
// }; | ||
// return digestAuth; | ||
// } | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Authentication, AuthType } from "../../utils/types"; | ||
import { getAuthType } from "./authentication"; | ||
|
||
/** | ||
* Helpers and utilities for endpoint Authentication details | ||
* Modelled on a Security Scheme Object https://spec.openapis.org/oas/v3.1.0#security-scheme-object | ||
*/ | ||
export interface HTTPAuth extends Authentication { | ||
type: "http"; | ||
} | ||
|
||
export interface BearerAuthHeader extends HTTPAuth { | ||
scheme: "Bearer"; | ||
in: "header"; | ||
} | ||
|
||
export interface BasicAuthHeader extends HTTPAuth { | ||
scheme: "Basic"; | ||
in: "header"; | ||
} | ||
|
||
export interface DigestAuthHeader extends HTTPAuth { | ||
scheme: "Digest"; | ||
in: "header"; | ||
} | ||
|
||
export type HTTPAuthHeaders = | ||
| DigestAuthHeader | ||
| BasicAuthHeader | ||
| BearerAuthHeader | ||
| undefined; | ||
|
||
export const parseHTTPAuthHeader = ( | ||
header: chrome.devtools.network.Request["request"]["headers"][0] | ||
): HTTPAuthHeaders => { | ||
const authType = getAuthType(header.value); | ||
if (authType === "basic") { | ||
const basicAuth: BasicAuthHeader = { | ||
id: AuthType.BASIC, | ||
type: "http", | ||
in: "header", | ||
scheme: "Basic", | ||
description: "", | ||
}; | ||
return basicAuth; | ||
} else if (authType === "bearer") { | ||
const bearerAuth: BearerAuthHeader = { | ||
id: AuthType.BEARER, | ||
type: "http", | ||
in: "header", | ||
scheme: "Bearer", | ||
description: "", | ||
}; | ||
return bearerAuth; | ||
} else if (authType === "digest") { | ||
const digestAuth: DigestAuthHeader = { | ||
id: AuthType.DIGEST, | ||
type: "http", | ||
in: "header", | ||
scheme: "Digest", | ||
description: "", | ||
}; | ||
return digestAuth; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { isEmpty } from "lodash"; | ||
import { Leaf } from "../../utils/types"; | ||
import { parseHTTPAuthHeader } from "./authentication-http"; | ||
|
||
export const getAuthType = (auth: string) => { | ||
const split = auth.split(" "); | ||
if (!split.length) return ""; | ||
return split[0].toLowerCase(); | ||
}; | ||
|
||
const AUTHORIZATION = "authorization"; | ||
|
||
type DetermineAuthFromHAR = (harRequest: chrome.devtools.network.Request) => Leaf['authentication'] | undefined; | ||
const determineAuthFromHAR: DetermineAuthFromHAR = (harRequest) => { | ||
const finalAuth: Leaf['authentication'] = {}; | ||
const foundAuthHeader = harRequest.request.headers.find( | ||
(head) => head.name.toLowerCase() === AUTHORIZATION | ||
); | ||
const authHeaders = foundAuthHeader ? parseHTTPAuthHeader(foundAuthHeader) : undefined; | ||
if (!isEmpty(authHeaders)) finalAuth[authHeaders.id] = authHeaders; | ||
if (isEmpty(finalAuth)) return undefined; | ||
return finalAuth; | ||
}; | ||
|
||
export default determineAuthFromHAR; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.