@sylphx/auth 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/client.d.ts +16 -0
- package/dist/client.js +16 -0
- package/dist/server.d.ts +3 -1
- package/dist/server.js +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,6 +24,24 @@ Request URL reflects the trusted public origin, or supply `isPublicRequest`
|
|
|
24
24
|
with your edge's trusted-origin verification. Never trust caller-supplied
|
|
25
25
|
forwarded headers alone.
|
|
26
26
|
|
|
27
|
+
### Sylphx Hosting
|
|
28
|
+
|
|
29
|
+
Set `trustSylphxEdge: true` on the handler when **all ingress paths to it are
|
|
30
|
+
restricted to managed literal-host routes** that overwrite `Sylphx-Edge`,
|
|
31
|
+
`X-Forwarded-Host` and `X-Forwarded-Proto` for the matched public hostname.
|
|
32
|
+
This admits the rewritten internal request URL only with `Sylphx-Edge: public`,
|
|
33
|
+
a single exact forwarded host equal to the configured `origin`’s host (including
|
|
34
|
+
any non-default port), and `X-Forwarded-Proto: https`. Partial or contradictory
|
|
35
|
+
headers are rejected even when the request URL matches. With no edge headers,
|
|
36
|
+
the request URL must match the configured HTTPS origin as before.
|
|
37
|
+
|
|
38
|
+
Do not enable this on wildcard, direct-to-service, or other routes where a
|
|
39
|
+
caller can supply either forwarded header. The edge marker is not a credential,
|
|
40
|
+
and the HTTPS stamp is the configured public scheme, not a TLS observation.
|
|
41
|
+
Remove a hand-rolled `isPublicRequest` when adopting this option; that callback
|
|
42
|
+
otherwise retains precedence. Browser Origin and fetch-metadata checks, OAuth
|
|
43
|
+
state checks, and redirect destinations are unchanged.
|
|
44
|
+
|
|
27
45
|
| Route | Method | Input / result |
|
|
28
46
|
| --- | --- | --- |
|
|
29
47
|
| `/auth/config` | GET | Public capabilities only; no credentials or upstream URLs |
|
package/dist/client.d.ts
CHANGED
|
@@ -4,6 +4,22 @@ export declare const providers: {
|
|
|
4
4
|
readonly apple: readonly ["Apple", "https://appleid.apple.com/auth/authorize"];
|
|
5
5
|
readonly facebook: readonly ["Facebook", "https://www.facebook.com/v25.0/dialog/oauth"];
|
|
6
6
|
readonly microsoft: readonly ["Microsoft", "https://login.microsoftonline.com/common/oauth2/v2.0/authorize"];
|
|
7
|
+
readonly line: readonly ["LINE", "https://access.line.me/oauth2/v2.1/authorize"];
|
|
8
|
+
readonly kakao: readonly ["Kakao", "https://kauth.kakao.com/oauth/authorize"];
|
|
9
|
+
readonly discord: readonly ["Discord", "https://discord.com/oauth2/authorize"];
|
|
10
|
+
readonly x: readonly ["X", "https://x.com/i/oauth2/authorize"];
|
|
11
|
+
readonly twitch: readonly ["Twitch", "https://id.twitch.tv/oauth2/authorize"];
|
|
12
|
+
readonly linkedin: readonly ["LinkedIn", "https://www.linkedin.com/oauth/v2/authorization"];
|
|
13
|
+
readonly slack: readonly ["Slack", "https://slack.com/openid/connect/authorize"];
|
|
14
|
+
readonly gitlab: readonly ["GitLab", "https://gitlab.com/oauth/authorize"];
|
|
15
|
+
readonly bitbucket: readonly ["Bitbucket", "https://bitbucket.org/site/oauth2/authorize"];
|
|
16
|
+
readonly spotify: readonly ["Spotify", "https://accounts.spotify.com/authorize"];
|
|
17
|
+
readonly tiktok: readonly ["TikTok", "https://www.tiktok.com/v2/auth/authorize/"];
|
|
18
|
+
readonly notion: readonly ["Notion", "https://api.notion.com/v1/oauth/authorize"];
|
|
19
|
+
readonly linear: readonly ["Linear", "https://linear.app/oauth/authorize"];
|
|
20
|
+
readonly atlassian: readonly ["Atlassian", "https://auth.atlassian.com/authorize"];
|
|
21
|
+
readonly huggingface: readonly ["Hugging Face", "https://huggingface.co/oauth/authorize"];
|
|
22
|
+
readonly figma: readonly ["Figma", "https://www.figma.com/oauth"];
|
|
7
23
|
};
|
|
8
24
|
export type Provider = keyof typeof providers;
|
|
9
25
|
export type AuthMethod = 'oauth' | 'password' | 'otp' | 'passkey';
|
package/dist/client.js
CHANGED
|
@@ -4,6 +4,22 @@ export const providers = {
|
|
|
4
4
|
apple: ['Apple', 'https://appleid.apple.com/auth/authorize'],
|
|
5
5
|
facebook: ['Facebook', 'https://www.facebook.com/v25.0/dialog/oauth'],
|
|
6
6
|
microsoft: ['Microsoft', 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'],
|
|
7
|
+
line: ['LINE', 'https://access.line.me/oauth2/v2.1/authorize'],
|
|
8
|
+
kakao: ['Kakao', 'https://kauth.kakao.com/oauth/authorize'],
|
|
9
|
+
discord: ['Discord', 'https://discord.com/oauth2/authorize'],
|
|
10
|
+
x: ['X', 'https://x.com/i/oauth2/authorize'],
|
|
11
|
+
twitch: ['Twitch', 'https://id.twitch.tv/oauth2/authorize'],
|
|
12
|
+
linkedin: ['LinkedIn', 'https://www.linkedin.com/oauth/v2/authorization'],
|
|
13
|
+
slack: ['Slack', 'https://slack.com/openid/connect/authorize'],
|
|
14
|
+
gitlab: ['GitLab', 'https://gitlab.com/oauth/authorize'],
|
|
15
|
+
bitbucket: ['Bitbucket', 'https://bitbucket.org/site/oauth2/authorize'],
|
|
16
|
+
spotify: ['Spotify', 'https://accounts.spotify.com/authorize'],
|
|
17
|
+
tiktok: ['TikTok', 'https://www.tiktok.com/v2/auth/authorize/'],
|
|
18
|
+
notion: ['Notion', 'https://api.notion.com/v1/oauth/authorize'],
|
|
19
|
+
linear: ['Linear', 'https://linear.app/oauth/authorize'],
|
|
20
|
+
atlassian: ['Atlassian', 'https://auth.atlassian.com/authorize'],
|
|
21
|
+
huggingface: ['Hugging Face', 'https://huggingface.co/oauth/authorize'],
|
|
22
|
+
figma: ['Figma', 'https://www.figma.com/oauth'],
|
|
7
23
|
};
|
|
8
24
|
export function isProvider(id) {
|
|
9
25
|
return typeof id === 'string' && Object.hasOwn(providers, id);
|
package/dist/server.d.ts
CHANGED
|
@@ -78,7 +78,9 @@ export type SylphxAuthOptions = {
|
|
|
78
78
|
allowReturnTo?: (path: string) => boolean;
|
|
79
79
|
flowCookie?: string;
|
|
80
80
|
sessionCookie?: string;
|
|
81
|
-
/**
|
|
81
|
+
/** Opt in only on managed literal-host routes that overwrite all three Sylphx Edge headers. */
|
|
82
|
+
trustSylphxEdge?: boolean;
|
|
83
|
+
/** Override the public request check, including the built-in Sylphx Edge policy. */
|
|
82
84
|
isPublicRequest?: (request: Request) => boolean;
|
|
83
85
|
/** Only for hosts with an existing authoritative session and revocation mechanism. */
|
|
84
86
|
session?: SessionAdapter;
|
package/dist/server.js
CHANGED
|
@@ -48,6 +48,7 @@ function portalStart(provider, row, discovery, pin, slug) {
|
|
|
48
48
|
}
|
|
49
49
|
export function createSylphxAuthHandler(options) {
|
|
50
50
|
const origin = requireOrigin(options.origin);
|
|
51
|
+
const publicHost = new URL(origin).host;
|
|
51
52
|
const api = requireOrigin(options.authApiOrigin);
|
|
52
53
|
const tenantAuthOrigin = options.tenantAuthOrigin === undefined ? undefined : requireOrigin(options.tenantAuthOrigin);
|
|
53
54
|
if (tenantAuthOrigin && tenantAuthOrigin === api)
|
|
@@ -329,9 +330,21 @@ export function createSylphxAuthHandler(options) {
|
|
|
329
330
|
return fail();
|
|
330
331
|
}
|
|
331
332
|
}
|
|
333
|
+
function isPublicRequest(request, url) {
|
|
334
|
+
if (options.trustSylphxEdge === true) {
|
|
335
|
+
const edge = request.headers.get('sylphx-edge');
|
|
336
|
+
const host = request.headers.get('x-forwarded-host');
|
|
337
|
+
const proto = request.headers.get('x-forwarded-proto');
|
|
338
|
+
if (edge !== null || host !== null || proto !== null) {
|
|
339
|
+
// Exact comparisons reject combined duplicates and never choose a list entry.
|
|
340
|
+
return edge === 'public' && host === publicHost && proto === 'https';
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return url.origin === origin;
|
|
344
|
+
}
|
|
332
345
|
return async (request) => {
|
|
333
346
|
const url = new URL(request.url);
|
|
334
|
-
if (!(options.isPublicRequest?.(request) ?? url
|
|
347
|
+
if (!(options.isPublicRequest?.(request) ?? isPublicRequest(request, url)))
|
|
335
348
|
return problem('not_allowed', 403);
|
|
336
349
|
const { pathname } = url;
|
|
337
350
|
const identity = transport(request, fetchUpstream, api);
|