Skip to content

Commit 7f13873

Browse files
authored
Merge pull request #437 from shapehq/enhancement/support-basic-auth
Supports basic auth in remote specifications
2 parents fcfa808 + 75f30ec commit 7f13873

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/app/api/proxy/route.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,20 @@ async function downloadFile(params: {
5555
const { url, maxBytes, timeoutInSeconds } = params
5656
const abortController = new AbortController()
5757
const timeoutSignal = AbortSignal.timeout(timeoutInSeconds * 1000)
58-
const response = await fetch(url, {
58+
const headers: {[key: string]: string} = {}
59+
// Extract basic auth from URL and construct an Authorization header instead.
60+
if ((url.username && url.username.length > 0) || (url.password && url.password.length > 0)) {
61+
const username = decodeURIComponent(url.username)
62+
const password = decodeURIComponent(url.password)
63+
headers["Authorization"] = "Basic " + btoa(`${username}:${password}`)
64+
}
65+
// Make sure basic auth is removed from URL.
66+
const urlWithoutAuth = url
67+
urlWithoutAuth.username = ""
68+
urlWithoutAuth.password = ""
69+
const response = await fetch(urlWithoutAuth, {
70+
method: "GET",
71+
headers,
5972
signal: AbortSignal.any([abortController.signal, timeoutSignal])
6073
})
6174
if (!response.body) {

src/features/sidebar/view/internal/primary/Container.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const PrimaryContainer = ({
1717
}) => {
1818
return (
1919
<>
20-
<_PrimaryContainer
20+
<InnerPrimaryContainer
2121
variant="temporary"
2222
width={width}
2323
isOpen={isOpen}
@@ -26,23 +26,23 @@ const PrimaryContainer = ({
2626
sx={{ display: { xs: "block", sm: "none" } }}
2727
>
2828
{children}
29-
</_PrimaryContainer>
30-
<_PrimaryContainer
29+
</InnerPrimaryContainer>
30+
<InnerPrimaryContainer
3131
variant="persistent"
3232
width={width}
3333
isOpen={isOpen}
3434
keepMounted={false}
3535
sx={{ display: { xs: "none", sm: "block" } }}
3636
>
3737
{children}
38-
</_PrimaryContainer>
38+
</InnerPrimaryContainer>
3939
</>
4040
)
4141
}
4242

4343
export default PrimaryContainer
4444

45-
const _PrimaryContainer = ({
45+
const InnerPrimaryContainer = ({
4646
variant,
4747
width,
4848
isOpen,

src/features/sidebar/view/internal/secondary/Container.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ const SecondaryContainer = ({
1717
const sx = { overflow: "hidden" }
1818
return (
1919
<>
20-
<_SecondaryContainer
20+
<InnerSecondaryContainer
21+
2122
sidebarWidth={isSM ? sidebarWidth : 0}
2223
isSidebarOpen={isSM ? offsetContent: false}
2324
sx={{ ...sx }}
2425
>
2526
{children}
26-
</_SecondaryContainer>
27+
</InnerSecondaryContainer
28+
>
2729
</>
2830
)
2931
}
@@ -52,7 +54,7 @@ const WrapperStack = styled(Stack, {
5254
})
5355
}))
5456

55-
const _SecondaryContainer = ({
57+
const InnerSecondaryContainer = ({
5658
sidebarWidth,
5759
isSidebarOpen,
5860
children,

0 commit comments

Comments
 (0)