-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update packages & replace request dependency (#60)
- Loading branch information
Showing
16 changed files
with
3,164 additions
and
2,967 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,13 @@ | ||
export const defaultForwardedHeaders = [ | ||
"accept", | ||
"accept-charset", | ||
"accept-encoding", | ||
"accept-language", | ||
"authorization", | ||
"cache-control", | ||
"content-type", | ||
"cookie", | ||
"host", | ||
"user-agent", | ||
"referer", | ||
] |
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,26 @@ | ||
import { type CreateApiHandlerOptions } from "../type/create-api-handler-options" | ||
|
||
export function getBaseUrl(options: CreateApiHandlerOptions) { | ||
let baseUrl = options.fallbackToPlayground | ||
? "https://playground.projects.oryapis.com/" | ||
: "" | ||
|
||
if (process.env.ORY_SDK_URL) { | ||
baseUrl = process.env.ORY_SDK_URL | ||
} | ||
|
||
if (process.env.ORY_KRATOS_URL) { | ||
baseUrl = process.env.ORY_KRATOS_URL | ||
} | ||
|
||
if (process.env.ORY_SDK_URL && process.env.ORY_KRATOS_URL) { | ||
throw new Error("Only one of ORY_SDK_URL or ORY_KRATOS_URL can be set.") | ||
} | ||
|
||
if (options.apiBaseUrlOverride) { | ||
baseUrl = options.apiBaseUrlOverride | ||
} | ||
|
||
return baseUrl.replace(/\/$/, "") | ||
} | ||
export { CreateApiHandlerOptions } |
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,71 @@ | ||
import { guessCookieDomain } from "./get-cookie-domain" | ||
|
||
describe("cookie guesser", () => { | ||
test("uses force domain", async () => { | ||
expect( | ||
guessCookieDomain("https://localhost", { | ||
forceCookieDomain: "some-domain", | ||
}), | ||
).toEqual("some-domain") | ||
}) | ||
|
||
test("does not use any guessing domain", async () => { | ||
expect( | ||
guessCookieDomain("https://localhost", { | ||
dontUseTldForCookieDomain: true, | ||
}), | ||
).toEqual(undefined) | ||
}) | ||
|
||
test("is not confused by invalid data", async () => { | ||
expect( | ||
guessCookieDomain("5qw5tare4g", { | ||
dontUseTldForCookieDomain: true, | ||
}), | ||
).toEqual(undefined) | ||
expect( | ||
guessCookieDomain("https://123.123.123.123.123", { | ||
dontUseTldForCookieDomain: true, | ||
}), | ||
).toEqual(undefined) | ||
}) | ||
|
||
test("is not confused by IP", async () => { | ||
expect( | ||
guessCookieDomain("https://123.123.123.123", { | ||
dontUseTldForCookieDomain: true, | ||
}), | ||
).toEqual(undefined) | ||
expect( | ||
guessCookieDomain("https://2001:0db8:0000:0000:0000:ff00:0042:8329", { | ||
dontUseTldForCookieDomain: true, | ||
}), | ||
).toEqual(undefined) | ||
}) | ||
|
||
test("uses TLD", async () => { | ||
expect(guessCookieDomain("https://foo.localhost", {})).toEqual( | ||
"foo.localhost", | ||
) | ||
|
||
expect(guessCookieDomain("https://foo.localhost:1234", {})).toEqual( | ||
"foo.localhost", | ||
) | ||
|
||
expect( | ||
guessCookieDomain( | ||
"https://spark-public.s3.amazonaws.com/dataanalysis/loansData.csv", | ||
{}, | ||
), | ||
).toEqual("spark-public.s3.amazonaws.com") | ||
|
||
expect(guessCookieDomain("spark-public.s3.amazonaws.com", {})).toEqual( | ||
"spark-public.s3.amazonaws.com", | ||
) | ||
|
||
expect(guessCookieDomain("https://localhost/123", {})).toEqual("localhost") | ||
expect(guessCookieDomain("https://localhost:1234/123", {})).toEqual( | ||
"localhost", | ||
) | ||
}) | ||
}) |
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,27 @@ | ||
import tldjs from "tldjs" | ||
import { CreateApiHandlerOptions } from "./get-base-url" | ||
|
||
export function guessCookieDomain( | ||
url: string | undefined, | ||
options: CreateApiHandlerOptions, | ||
) { | ||
if (!url || options.forceCookieDomain) { | ||
return options.forceCookieDomain | ||
} | ||
|
||
if (options.dontUseTldForCookieDomain) { | ||
return undefined | ||
} | ||
|
||
const parsed = tldjs.parse(url || "") | ||
|
||
if (!parsed.isValid || parsed.isIp) { | ||
return undefined | ||
} | ||
|
||
if (!parsed.domain) { | ||
return parsed.hostname | ||
} | ||
|
||
return parsed.domain | ||
} |
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,18 @@ | ||
export function processLocationHeader( | ||
locationHeaderValue: string, | ||
baseUrl: string, | ||
) { | ||
if (locationHeaderValue.startsWith(baseUrl)) { | ||
return locationHeaderValue.replace(baseUrl, "/api/.ory") | ||
} | ||
|
||
if ( | ||
locationHeaderValue.startsWith("/api/kratos/public/") || | ||
locationHeaderValue.startsWith("/self-service/") || | ||
locationHeaderValue.startsWith("/ui/") | ||
) { | ||
return "/api/.ory" + locationHeaderValue | ||
} | ||
|
||
return locationHeaderValue | ||
} |
Oops, something went wrong.