@starci/auth 0.4.0 → 0.6.0
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/CHANGELOG.md +17 -0
- package/README.md +104 -13
- package/dist/client/oidc/index.d.ts +5 -0
- package/dist/client/oidc/index.js +3 -0
- package/dist/client/oidc/oidc-client.d.ts +85 -0
- package/dist/client/oidc/oidc-client.js +304 -0
- package/dist/client/oidc/pkce.d.ts +15 -0
- package/dist/client/oidc/pkce.js +29 -0
- package/dist/contracts/index.d.ts +12 -0
- package/dist/contracts/index.js +14 -0
- package/dist/contracts/oidc.d.ts +148 -0
- package/dist/contracts/oidc.js +68 -0
- package/dist/oidc/admin.d.ts +42 -0
- package/dist/oidc/admin.js +139 -0
- package/dist/oidc/broker.d.ts +57 -0
- package/dist/oidc/broker.js +77 -0
- package/dist/oidc/client.d.ts +58 -0
- package/dist/oidc/client.js +119 -0
- package/dist/oidc/discovery.d.ts +23 -0
- package/dist/oidc/discovery.js +64 -0
- package/dist/oidc/errors.d.ts +10 -0
- package/dist/oidc/errors.js +10 -0
- package/dist/oidc/grants.d.ts +41 -0
- package/dist/oidc/grants.js +82 -0
- package/dist/oidc/index.d.ts +35 -0
- package/dist/oidc/index.js +18 -0
- package/dist/oidc/issuers/github-actions.d.ts +54 -0
- package/dist/oidc/issuers/github-actions.js +84 -0
- package/dist/oidc/issuers/google.d.ts +30 -0
- package/dist/oidc/issuers/google.js +39 -0
- package/dist/oidc/issuers/index.d.ts +8 -0
- package/dist/oidc/issuers/index.js +4 -0
- package/dist/oidc/issuers/issuer.d.ts +79 -0
- package/dist/oidc/issuers/issuer.js +39 -0
- package/dist/oidc/issuers/keycloak.d.ts +26 -0
- package/dist/oidc/issuers/keycloak.js +41 -0
- package/dist/oidc/jwks.d.ts +26 -0
- package/dist/oidc/jwks.js +80 -0
- package/dist/oidc/oidc.d.ts +32 -0
- package/dist/oidc/oidc.js +21 -0
- package/dist/oidc/oidc.module.d.ts +34 -0
- package/dist/oidc/oidc.module.js +51 -0
- package/dist/oidc/oidc.tokens.d.ts +18 -0
- package/dist/oidc/oidc.tokens.js +18 -0
- package/dist/oidc/options.d.ts +119 -0
- package/dist/oidc/options.js +98 -0
- package/dist/oidc/primitives.d.ts +15 -0
- package/dist/oidc/primitives.js +11 -0
- package/dist/oidc/refresh.d.ts +10 -0
- package/dist/oidc/refresh.js +24 -0
- package/dist/oidc/roles.d.ts +12 -0
- package/dist/oidc/roles.js +51 -0
- package/dist/oidc/tokens.d.ts +26 -0
- package/dist/oidc/tokens.js +79 -0
- package/dist/oidc/transport.d.ts +8 -0
- package/dist/oidc/transport.js +19 -0
- package/dist/oidc/verifier.d.ts +24 -0
- package/dist/oidc/verifier.js +64 -0
- package/dist/server/auth.module.d.ts +1 -1
- package/dist/server/auth.module.js +20 -6
- package/dist/server/auth.tokens.d.ts +2 -0
- package/dist/server/auth.tokens.js +2 -0
- package/dist/server/doors.d.ts +14 -8
- package/dist/server/doors.js +22 -11
- package/dist/server/errors.d.ts +2 -2
- package/dist/server/errors.js +3 -5
- package/dist/server/flows.d.ts +13 -5
- package/dist/server/flows.js +40 -20
- package/dist/server/index.d.ts +7 -7
- package/dist/server/index.js +3 -4
- package/dist/server/options.d.ts +11 -13
- package/dist/server/ports.d.ts +8 -1
- package/dist/server/primitives.d.ts +0 -2
- package/dist/server/primitives.js +2 -3
- package/dist/server/providers/github.d.ts +59 -0
- package/dist/server/providers/github.js +111 -0
- package/dist/server/providers/google.d.ts +56 -0
- package/dist/server/providers/google.js +87 -0
- package/dist/server/providers/index.d.ts +14 -0
- package/dist/server/providers/index.js +9 -0
- package/dist/server/providers/oauth-state.d.ts +47 -0
- package/dist/server/providers/oauth-state.js +74 -0
- package/dist/server/providers/provider.d.ts +58 -0
- package/dist/server/providers/provider.js +32 -0
- package/dist/server/providers/registry.d.ts +30 -0
- package/dist/server/providers/registry.js +37 -0
- package/dist/server/strategies.d.ts +3 -18
- package/dist/server/strategies.js +2 -41
- package/dist/server/verifier.d.ts +1 -1
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.js +2 -0
- package/dist/testing/oidc.d.ts +175 -0
- package/dist/testing/oidc.js +493 -0
- package/package.json +24 -5
- package/dist/server/google-state.d.ts +0 -33
- package/dist/server/google-state.js +0 -73
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { AUTH_DOORS } from "../contracts/index.js";
|
|
2
|
-
import { cookieValue, sameSitePath, sameValue } from "./primitives.js";
|
|
3
|
-
/** The cookie that carries one Google round trip, when the options name none. */
|
|
4
|
-
export const DEFAULT_GOOGLE_STATE_COOKIE = "auth_google_state";
|
|
5
|
-
/** The only path the state cookie is sent to. */
|
|
6
|
-
export const GOOGLE_STATE_PATH = AUTH_DOORS.google;
|
|
7
|
-
/** How long a Google round trip may take, in milliseconds. */
|
|
8
|
-
export const GOOGLE_STATE_TTL_MS = 600_000;
|
|
9
|
-
/**
|
|
10
|
-
* The state store passport-oauth2 calls for `state` and PKCE without a server session: the handle (echoed as `state`), the code
|
|
11
|
-
* verifier and the landing path travel in a signed, httpOnly cookie that only the callback path receives, and the handle is
|
|
12
|
-
* compared on return. The landing path is a same-site path only, so the callback can never redirect off the web origin.
|
|
13
|
-
*/
|
|
14
|
-
export class GoogleStateClient {
|
|
15
|
-
#tokens;
|
|
16
|
-
#clock;
|
|
17
|
-
#ids;
|
|
18
|
-
#returnOrigin;
|
|
19
|
-
#cookie;
|
|
20
|
-
constructor(deps) {
|
|
21
|
-
this.#tokens = deps.tokens;
|
|
22
|
-
this.#clock = deps.clock;
|
|
23
|
-
this.#ids = deps.ids;
|
|
24
|
-
this.#returnOrigin = deps.options.returnOrigin;
|
|
25
|
-
this.#cookie = deps.options.google?.stateCookie ?? DEFAULT_GOOGLE_STATE_COOKIE;
|
|
26
|
-
}
|
|
27
|
-
/** The name of the state cookie. */
|
|
28
|
-
get cookieName() {
|
|
29
|
-
return this.#cookie;
|
|
30
|
-
}
|
|
31
|
-
/** Called by passport-oauth2 on the outbound leg (the five-argument PKCE form). */
|
|
32
|
-
store(req, verifier, _state, _meta, done) {
|
|
33
|
-
const handle = this.#ids.next();
|
|
34
|
-
const signed = this.#tokens.signState({
|
|
35
|
-
w: handle,
|
|
36
|
-
u: verifier,
|
|
37
|
-
r: this.#landingOf(req),
|
|
38
|
-
e: this.#clock.now().getTime() + GOOGLE_STATE_TTL_MS,
|
|
39
|
-
p: "google",
|
|
40
|
-
});
|
|
41
|
-
req.res?.cookie(this.#cookie, signed, {
|
|
42
|
-
httpOnly: true,
|
|
43
|
-
secure: true,
|
|
44
|
-
sameSite: "lax",
|
|
45
|
-
path: GOOGLE_STATE_PATH,
|
|
46
|
-
maxAge: GOOGLE_STATE_TTL_MS,
|
|
47
|
-
});
|
|
48
|
-
done(null, handle);
|
|
49
|
-
}
|
|
50
|
-
/** The same-site path to land on: the requested return address when it is a path, or an absolute address on the web origin; else the root. */
|
|
51
|
-
#landingOf(req) {
|
|
52
|
-
const { returnTo, next } = req.query ?? {};
|
|
53
|
-
const wanted = typeof returnTo === "string" ? returnTo : next;
|
|
54
|
-
if (typeof wanted !== "string")
|
|
55
|
-
return "/";
|
|
56
|
-
if (!URL.canParse(wanted))
|
|
57
|
-
return sameSitePath(wanted, "/");
|
|
58
|
-
const url = new URL(wanted);
|
|
59
|
-
return url.origin === this.#returnOrigin ? sameSitePath(`${url.pathname}${url.search}`, "/") : "/";
|
|
60
|
-
}
|
|
61
|
-
/** Called by passport-oauth2 on the return leg (the meta form, since this method takes four arguments): the cookie must be ours, unexpired and carry the same handle as `state`. */
|
|
62
|
-
verify(req, providedState, _meta, done) {
|
|
63
|
-
const header = req.headers.cookie;
|
|
64
|
-
const raw = cookieValue(Array.isArray(header) ? header.join("; ") : (header ?? ""), this.#cookie);
|
|
65
|
-
req.res?.clearCookie(this.#cookie, { httpOnly: true, secure: true, sameSite: "lax", path: GOOGLE_STATE_PATH });
|
|
66
|
-
const state = raw === "" ? null : this.#tokens.verifyState(raw, this.#clock.now());
|
|
67
|
-
if (state?.p !== "google" || typeof providedState !== "string" || !sameValue(state.w, providedState)) {
|
|
68
|
-
done(null, false, { message: "state" });
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
done(null, state.u, { next: sameSitePath(state.r, "/") });
|
|
72
|
-
}
|
|
73
|
-
}
|