@deslop/auth 0.1.1267 → 0.1.1270
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/dist/client/assets/(home)-DKf5eDUb.js +1 -0
- package/dist/client/assets/components-BZR6Gw96.js +1 -0
- package/dist/client/assets/effect-DudpODeb.js +17 -0
- package/dist/client/assets/index-9IPEWiLw.css +2 -0
- package/dist/client/assets/index-BRMDqv31.js +2 -0
- package/dist/client/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/client/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/client/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/client/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/client/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/client/assets/people-BOAgfoXB.js +1 -0
- package/dist/client/assets/{react-COyt-gOi.js → react-CYMlNKV3.js} +3 -3
- package/dist/client/assets/route-CN9FIiGp.js +1 -0
- package/dist/client/assets/useValueChanged-C5RxbHd1.js +1 -0
- package/dist/client/assets/utils-BpQYtL_g.js +2 -0
- package/dist/client/index.html +5 -5
- package/dist/server.js +514 -373
- package/package.json +2 -2
- package/dist/client/assets/(home)-zPVOH7Wu.js +0 -20
- package/dist/client/assets/Check.es-C9l513Ch.js +0 -1
- package/dist/client/assets/components-CxZlmD_H.js +0 -1
- package/dist/client/assets/dialog-DbVw_5V8.js +0 -1
- package/dist/client/assets/effect-CarHrcH-.js +0 -17
- package/dist/client/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/dist/client/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/dist/client/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/dist/client/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/dist/client/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/dist/client/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/dist/client/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/dist/client/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/dist/client/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/dist/client/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/dist/client/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/dist/client/assets/index-D_zkN1kq.css +0 -2
- package/dist/client/assets/index-RSMneHpz.js +0 -2
- package/dist/client/assets/people-BeIXWDuU.js +0 -1
- package/dist/client/assets/route-CPuCWB2A.js +0 -41
- package/dist/client/assets/utils-BepQ-yTS.js +0 -2
package/dist/server.js
CHANGED
|
@@ -5700,6 +5700,28 @@ const toSeconds = (self) => match$7(fromInputUnsafe$1(self), {
|
|
|
5700
5700
|
onNegativeInfinity: () => -Infinity
|
|
5701
5701
|
});
|
|
5702
5702
|
/**
|
|
5703
|
+
* Converts a Duration to minutes.
|
|
5704
|
+
*
|
|
5705
|
+
* **Example** (Converting durations to minutes)
|
|
5706
|
+
*
|
|
5707
|
+
* ```ts import.meta.vitest
|
|
5708
|
+
* import { Duration } from "effect"
|
|
5709
|
+
*
|
|
5710
|
+
* Duration.toMinutes(Duration.seconds(120)) // => 2
|
|
5711
|
+
* Duration.toMinutes(Duration.hours(1)) // => 60
|
|
5712
|
+
* ```
|
|
5713
|
+
*
|
|
5714
|
+
* @stability stable
|
|
5715
|
+
* @category getters
|
|
5716
|
+
* @since 3.8.0
|
|
5717
|
+
*/
|
|
5718
|
+
const toMinutes = (self) => match$7(fromInputUnsafe$1(self), {
|
|
5719
|
+
onMillis: (millis) => millis / 6e4,
|
|
5720
|
+
onNanos: (nanos) => nanosToUnit(nanos, 6e10),
|
|
5721
|
+
onInfinity: () => Infinity,
|
|
5722
|
+
onNegativeInfinity: () => -Infinity
|
|
5723
|
+
});
|
|
5724
|
+
/**
|
|
5703
5725
|
* Gets the duration in nanoseconds as a bigint.
|
|
5704
5726
|
*
|
|
5705
5727
|
* **When to use**
|
|
@@ -7699,6 +7721,56 @@ const containsWith = (isEquivalent) => dual(2, (self, a) => {
|
|
|
7699
7721
|
* @since 2.0.0
|
|
7700
7722
|
*/
|
|
7701
7723
|
const contains = /*#__PURE__*/ containsWith(/*#__PURE__*/ asEquivalence());
|
|
7724
|
+
/**
|
|
7725
|
+
* Groups elements into a record by a key-returning function. Each key maps
|
|
7726
|
+
* to a `NonEmptyArray` of elements that produced that key.
|
|
7727
|
+
*
|
|
7728
|
+
* **When to use**
|
|
7729
|
+
*
|
|
7730
|
+
* Use to build buckets of elements indexed by a computed string or symbol key.
|
|
7731
|
+
*
|
|
7732
|
+
* **Details**
|
|
7733
|
+
*
|
|
7734
|
+
* Unlike `group` and `groupWith`, elements do not need to be adjacent to be
|
|
7735
|
+
* grouped together. The key function must return a `string` or `symbol`.
|
|
7736
|
+
*
|
|
7737
|
+
* **Gotchas**
|
|
7738
|
+
*
|
|
7739
|
+
* When the key function returns a finite union of string literals or unique
|
|
7740
|
+
* symbols, the result preserves those keys as optional properties because the
|
|
7741
|
+
* input may not produce every key. Open `string` and `symbol` key types retain
|
|
7742
|
+
* their record index signatures.
|
|
7743
|
+
*
|
|
7744
|
+
* **Example** (Grouping by a property)
|
|
7745
|
+
*
|
|
7746
|
+
* ```ts import.meta.vitest
|
|
7747
|
+
* import { Array } from "effect"
|
|
7748
|
+
*
|
|
7749
|
+
* const people = [
|
|
7750
|
+
* { name: "Alice", group: "A" },
|
|
7751
|
+
* { name: "Bob", group: "B" },
|
|
7752
|
+
* { name: "Charlie", group: "A" }
|
|
7753
|
+
* ]
|
|
7754
|
+
*
|
|
7755
|
+
* Object.keys(Array.groupBy(people, (person) => person.group)).join(",") // => "A,B"
|
|
7756
|
+
* ```
|
|
7757
|
+
*
|
|
7758
|
+
* @see {@link group} — group adjacent equal elements
|
|
7759
|
+
* @see {@link groupWith} — group adjacent elements by custom equality
|
|
7760
|
+
*
|
|
7761
|
+
* @stability stable
|
|
7762
|
+
* @category grouping
|
|
7763
|
+
* @since 2.0.0
|
|
7764
|
+
*/
|
|
7765
|
+
const groupBy = /*#__PURE__*/ dual(2, (self, f) => {
|
|
7766
|
+
const out = {};
|
|
7767
|
+
for (const a of self) {
|
|
7768
|
+
const k = f(a);
|
|
7769
|
+
if (Object.hasOwn(out, k)) out[k].push(a);
|
|
7770
|
+
else assignProperty(out, k, [a]);
|
|
7771
|
+
}
|
|
7772
|
+
return out;
|
|
7773
|
+
});
|
|
7702
7774
|
const hashBucketsAdd = (buckets, value) => {
|
|
7703
7775
|
const hash$6 = hash(value);
|
|
7704
7776
|
const bucket = buckets.get(hash$6);
|
|
@@ -28314,6 +28386,26 @@ const mkUint8Array$1 = (self) => map$5(runFold(self, () => ({
|
|
|
28314
28386
|
return result;
|
|
28315
28387
|
});
|
|
28316
28388
|
/**
|
|
28389
|
+
* Runs a channel until the first output element is available, returning it in
|
|
28390
|
+
* an `Option`.
|
|
28391
|
+
*
|
|
28392
|
+
* **Details**
|
|
28393
|
+
*
|
|
28394
|
+
* Returns `Option.some` with the first output element, or `Option.none` if the
|
|
28395
|
+
* channel completes without emitting output.
|
|
28396
|
+
*
|
|
28397
|
+
* @stability stable
|
|
28398
|
+
* @category running
|
|
28399
|
+
* @since 4.0.0
|
|
28400
|
+
*/
|
|
28401
|
+
const runHead$1 = (self) => suspend$2(() => {
|
|
28402
|
+
let head = none();
|
|
28403
|
+
return runWith$1(self, (pull) => pull.pipe(asSome, flatMap$2((head_) => {
|
|
28404
|
+
head = head_;
|
|
28405
|
+
return done$1();
|
|
28406
|
+
})), () => succeed$5(head));
|
|
28407
|
+
});
|
|
28408
|
+
/**
|
|
28317
28409
|
* Runs a channel to completion and returns the last output element in an
|
|
28318
28410
|
* `Option`.
|
|
28319
28411
|
*
|
|
@@ -30401,6 +30493,27 @@ const runFoldEffect = /*#__PURE__*/ dual(3, (self, initial, f) => runFoldEffect$
|
|
|
30401
30493
|
}), () => s);
|
|
30402
30494
|
}));
|
|
30403
30495
|
/**
|
|
30496
|
+
* Runs the stream and returns the first element as an `Option`.
|
|
30497
|
+
*
|
|
30498
|
+
* **Example** (Getting the first stream value)
|
|
30499
|
+
*
|
|
30500
|
+
* ```ts import.meta.vitest
|
|
30501
|
+
* import { Effect, Option, Stream } from "effect"
|
|
30502
|
+
*
|
|
30503
|
+
* const program = Effect.gen(function*() {
|
|
30504
|
+
* const head = yield* Stream.runHead(Stream.make(1, 2, 3))
|
|
30505
|
+
* Option.getOrThrow(head) // => 1
|
|
30506
|
+
* })
|
|
30507
|
+
*
|
|
30508
|
+
* await Effect.runPromise(program)
|
|
30509
|
+
* ```
|
|
30510
|
+
*
|
|
30511
|
+
* @stability stable
|
|
30512
|
+
* @category destructors
|
|
30513
|
+
* @since 2.0.0
|
|
30514
|
+
*/
|
|
30515
|
+
const runHead = (self) => map$5(runHead$1(self.channel), map$11(getUnsafe$1(0)));
|
|
30516
|
+
/**
|
|
30404
30517
|
* Runs the stream and returns the last element as an `Option`.
|
|
30405
30518
|
*
|
|
30406
30519
|
* **When to use**
|
|
@@ -89526,7 +89639,6 @@ var AuthError = class extends TaggedError()("AuthError", {
|
|
|
89526
89639
|
"invalid_client_metadata",
|
|
89527
89640
|
"invalid_redirect_uri",
|
|
89528
89641
|
"invalid_grant",
|
|
89529
|
-
"invalid_target",
|
|
89530
89642
|
"invalid_scope",
|
|
89531
89643
|
"unsupported_grant_type",
|
|
89532
89644
|
"unsupported_response_type",
|
|
@@ -90320,6 +90432,12 @@ function layerOtlp(serviceName, url, runtime, version) {
|
|
|
90320
90432
|
const AUTH_URL = "https://auth.mp281x.xyz";
|
|
90321
90433
|
const ISSUER_PATH = "/api/auth";
|
|
90322
90434
|
const APPS_PATH = "/api/apps";
|
|
90435
|
+
const COOKIE = {
|
|
90436
|
+
httpOnly: true,
|
|
90437
|
+
path: "/",
|
|
90438
|
+
sameSite: "lax",
|
|
90439
|
+
secure: true
|
|
90440
|
+
};
|
|
90323
90441
|
const SESSION_COOKIE = "__Host-session";
|
|
90324
90442
|
function matchingSessions(saved, userId) {
|
|
90325
90443
|
return sort(filter$6(getSomes(saved), (session) => session.value.user.id === userId), mapInput(flip$1(Number$6), (session) => session.value.expiresAt));
|
|
@@ -91835,13 +91953,6 @@ function layerMcpAuth(resource) {
|
|
|
91835
91953
|
// ../../packages/runtime/src/server.ts
|
|
91836
91954
|
const LOOPBACK = /^(?:localhost|\d{1,3}(?:\.\d{1,3}){3}|\[[\da-f:.]+\])$/iu;
|
|
91837
91955
|
const OTLP = ["/v1/traces", "/v1/logs"];
|
|
91838
|
-
const COOKIE$1 = {
|
|
91839
|
-
httpOnly: true,
|
|
91840
|
-
path: "/",
|
|
91841
|
-
sameSite: "lax",
|
|
91842
|
-
secure: true
|
|
91843
|
-
};
|
|
91844
|
-
const SIGN_IN_COOKIE = "__Host-sign-in";
|
|
91845
91956
|
const packageRoot = match$1(endsWith(".ts")(import.meta.url), {
|
|
91846
91957
|
onFalse: () => fileURLToPath(new URL("..", import.meta.url)),
|
|
91847
91958
|
onTrue: cwd
|
|
@@ -91976,112 +92087,6 @@ const layerRoutes = use((router) => gen(function* () {
|
|
|
91976
92087
|
}, { headers: { "cache-control": "no-store" } });
|
|
91977
92088
|
}));
|
|
91978
92089
|
}));
|
|
91979
|
-
const SignInState = fromJsonString(Struct({
|
|
91980
|
-
next: String$6,
|
|
91981
|
-
state: String$6,
|
|
91982
|
-
verifier: String$6
|
|
91983
|
-
}));
|
|
91984
|
-
const CallbackParams$1 = Struct({
|
|
91985
|
-
code: optionalKey(String$6),
|
|
91986
|
-
error: optionalKey(String$6),
|
|
91987
|
-
iss: optionalKey(String$6),
|
|
91988
|
-
state: optionalKey(String$6)
|
|
91989
|
-
});
|
|
91990
|
-
function signedOut(next, cause) {
|
|
91991
|
-
return as(logWarning("The sign-in did not complete", cause), expireCookieUnsafe(redirect(next), SIGN_IN_COOKIE, COOKIE$1));
|
|
91992
|
-
}
|
|
91993
|
-
function layerSignIn(issuer) {
|
|
91994
|
-
return use((router) => gen(function* () {
|
|
91995
|
-
const sessions = yield* Sessions;
|
|
91996
|
-
const random = yield* SecureRandom;
|
|
91997
|
-
const digest = yield* Digest;
|
|
91998
|
-
const canonical = new URL(yield* String$5("APP_URL")).origin;
|
|
91999
|
-
const callback = new URL(CALLBACK_PATH, canonical).href;
|
|
92000
|
-
const clientId = yield* cached(map$5(appName, (name) => clientIdOf({
|
|
92001
|
-
name: capitalize(name),
|
|
92002
|
-
redirects: [callback]
|
|
92003
|
-
})));
|
|
92004
|
-
function ended(headers) {
|
|
92005
|
-
return match$8(sessionIdOf(headers), {
|
|
92006
|
-
onNone: () => void_$1,
|
|
92007
|
-
onSome: (id) => ignore$1(sessions.end(id), {
|
|
92008
|
-
log: "Warn",
|
|
92009
|
-
message: "The session could not be ended"
|
|
92010
|
-
})
|
|
92011
|
-
});
|
|
92012
|
-
}
|
|
92013
|
-
function toNext(handle) {
|
|
92014
|
-
return flatMap$2(HttpServerRequest, (request) => match$8(filter$8(liftThrowable(() => new URL(new URL(request.url, canonical).searchParams.get("next") ?? canonical, canonical))(), (next) => next.origin === canonical), {
|
|
92015
|
-
onNone: () => succeed$5(empty({ status: 400 })),
|
|
92016
|
-
onSome: (next) => handle(request, next)
|
|
92017
|
-
}));
|
|
92018
|
-
}
|
|
92019
|
-
yield* router.add("GET", "/auth/sign-in", toNext(fnUntraced(function* (_, next) {
|
|
92020
|
-
const verifier = encode$3(yield* random.randomBytes(32));
|
|
92021
|
-
const state = encode$3(yield* random.randomBytes(16));
|
|
92022
|
-
const authorize = new URL(AUTHORIZE_PATH, issuer);
|
|
92023
|
-
authorize.search = `${new URLSearchParams({
|
|
92024
|
-
client_id: yield* clientId,
|
|
92025
|
-
code_challenge: encode$3(yield* digest.digest(sha256, new TextEncoder().encode(verifier))),
|
|
92026
|
-
code_challenge_method: "S256",
|
|
92027
|
-
redirect_uri: callback,
|
|
92028
|
-
response_type: "code",
|
|
92029
|
-
scope: "deslop offline_access",
|
|
92030
|
-
state
|
|
92031
|
-
})}`;
|
|
92032
|
-
return setCookieUnsafe(redirect(authorize.href), SIGN_IN_COOKIE, yield* encodeEffect(SignInState)({
|
|
92033
|
-
next: next.href,
|
|
92034
|
-
state,
|
|
92035
|
-
verifier
|
|
92036
|
-
}), {
|
|
92037
|
-
...COOKIE$1,
|
|
92038
|
-
maxAge: "10 minutes"
|
|
92039
|
-
});
|
|
92040
|
-
})));
|
|
92041
|
-
yield* router.add("GET", CALLBACK_PATH, gen(function* () {
|
|
92042
|
-
const request = yield* HttpServerRequest;
|
|
92043
|
-
return yield* match$8(yield* option$1(decodeUnknownEffect(SignInState)(request.cookies[SIGN_IN_COOKIE])), {
|
|
92044
|
-
onNone: () => signedOut(canonical, "The sign-in expired or began in another browser"),
|
|
92045
|
-
onSome: fnUntraced(function* (saved) {
|
|
92046
|
-
const started = yield* result$1(gen(function* () {
|
|
92047
|
-
const params = yield* schemaSearchParams(CallbackParams$1);
|
|
92048
|
-
if (params.state !== saved.state) return yield* AuthError.make({ message: "The sign-in began in another browser" });
|
|
92049
|
-
if (params.error !== void 0 || params.code === void 0) return yield* AuthError.make({ message: `Auth answered ${params.error ?? "without a code"}` });
|
|
92050
|
-
if (params.iss !== new URL("/api/auth", issuer).href) return yield* AuthError.make({ message: "The answer came from another issuer" });
|
|
92051
|
-
return yield* sessions.start({
|
|
92052
|
-
client_id: yield* clientId,
|
|
92053
|
-
code: params.code,
|
|
92054
|
-
code_verifier: saved.verifier,
|
|
92055
|
-
redirect_uri: callback
|
|
92056
|
-
});
|
|
92057
|
-
}));
|
|
92058
|
-
if (isFailure$1(started)) return yield* signedOut(saved.next, started.failure);
|
|
92059
|
-
return pipe(redirect(saved.next), expireCookieUnsafe(SIGN_IN_COOKIE, COOKIE$1), setCookieUnsafe(SESSION_COOKIE, started.success, {
|
|
92060
|
-
...COOKIE$1,
|
|
92061
|
-
maxAge: "365 days"
|
|
92062
|
-
}));
|
|
92063
|
-
})
|
|
92064
|
-
});
|
|
92065
|
-
}));
|
|
92066
|
-
yield* router.add("POST", "/auth/session", gen(function* () {
|
|
92067
|
-
const started = yield* result$1(pipe(schemaBodyJson(CodeGrant), rejected("The sign-in request is invalid"), flatMap$2(sessions.start)));
|
|
92068
|
-
if (isFailure$1(started)) return text(started.failure.message, failureOptions(started.failure, 400));
|
|
92069
|
-
return yield* schemaJson(SessionHandle)({ session: started.success }, { headers: { "cache-control": "no-store" } });
|
|
92070
|
-
}));
|
|
92071
|
-
yield* router.add("GET", "/auth/sign-out", toNext((request, next) => as(ended(request.headers), expireCookieUnsafe(redirect(`${new URL("/", issuer).href}?${new URLSearchParams({
|
|
92072
|
-
next: next.href,
|
|
92073
|
-
"sign-out": ""
|
|
92074
|
-
})}`), SESSION_COOKIE, COOKIE$1))));
|
|
92075
|
-
yield* router.add("POST", "/auth/sign-out", as(flatMap$2(HttpServerRequest, (request) => ended(request.headers)), empty({ status: 204 })));
|
|
92076
|
-
}));
|
|
92077
|
-
}
|
|
92078
|
-
const notConfigured = text("Sign-in is not configured for this app", { status: 503 });
|
|
92079
|
-
const layerSessionRoutes = unwrap$7(gen(function* () {
|
|
92080
|
-
return match$8(yield* option(String$5("AUTH_URL")), {
|
|
92081
|
-
onNone: () => mergeAll$1(add("GET", "/auth/sign-in", notConfigured), add("GET", "/auth/sign-out", notConfigured)),
|
|
92082
|
-
onSome: layerSignIn
|
|
92083
|
-
});
|
|
92084
|
-
}));
|
|
92085
92090
|
const layerAnnounce = effectDiscard(gen(function* () {
|
|
92086
92091
|
const origin = new URL(yield* String$5("APP_URL")).origin;
|
|
92087
92092
|
const client = pipe(yield* HttpClient, filterStatusOk, timeout("10 seconds"), retryTransient({
|
|
@@ -92211,6 +92216,113 @@ var AiGateway = class AiGateway extends Service$1()("@deslop/runtime/ai/service/
|
|
|
92211
92216
|
});
|
|
92212
92217
|
}));
|
|
92213
92218
|
};
|
|
92219
|
+
// ../../packages/runtime/src/auth/routes.ts
|
|
92220
|
+
const SIGN_IN_COOKIE = "__Host-sign-in";
|
|
92221
|
+
const SignInState = fromJsonString(Struct({
|
|
92222
|
+
next: String$6,
|
|
92223
|
+
state: String$6,
|
|
92224
|
+
verifier: String$6
|
|
92225
|
+
}));
|
|
92226
|
+
const CallbackParams$1 = Struct({
|
|
92227
|
+
code: optionalKey(String$6),
|
|
92228
|
+
error: optionalKey(String$6),
|
|
92229
|
+
iss: optionalKey(String$6),
|
|
92230
|
+
state: optionalKey(String$6)
|
|
92231
|
+
});
|
|
92232
|
+
function signedOut(next, cause) {
|
|
92233
|
+
return as(logWarning("The sign-in did not complete", cause), expireCookieUnsafe(redirect(next), SIGN_IN_COOKIE, COOKIE));
|
|
92234
|
+
}
|
|
92235
|
+
function layerSignIn(issuer) {
|
|
92236
|
+
return use((router) => gen(function* () {
|
|
92237
|
+
const sessions = yield* Sessions;
|
|
92238
|
+
const random = yield* SecureRandom;
|
|
92239
|
+
const digest = yield* Digest;
|
|
92240
|
+
const canonical = new URL(yield* String$5("APP_URL")).origin;
|
|
92241
|
+
const callback = new URL(CALLBACK_PATH, canonical).href;
|
|
92242
|
+
const clientId = yield* cached(map$5(appName, (name) => clientIdOf({
|
|
92243
|
+
name: capitalize(name),
|
|
92244
|
+
redirects: [callback]
|
|
92245
|
+
})));
|
|
92246
|
+
function ended(headers) {
|
|
92247
|
+
return match$8(sessionIdOf(headers), {
|
|
92248
|
+
onNone: () => void_$1,
|
|
92249
|
+
onSome: (id) => ignore$1(sessions.end(id), {
|
|
92250
|
+
log: "Warn",
|
|
92251
|
+
message: "The session could not be ended"
|
|
92252
|
+
})
|
|
92253
|
+
});
|
|
92254
|
+
}
|
|
92255
|
+
function toNext(handle) {
|
|
92256
|
+
return flatMap$2(HttpServerRequest, (request) => match$8(filter$8(liftThrowable(() => new URL(new URL(request.url, canonical).searchParams.get("next") ?? canonical, canonical))(), (next) => next.origin === canonical), {
|
|
92257
|
+
onNone: () => succeed$5(empty({ status: 400 })),
|
|
92258
|
+
onSome: (next) => handle(request, next)
|
|
92259
|
+
}));
|
|
92260
|
+
}
|
|
92261
|
+
yield* router.add("GET", "/auth/sign-in", toNext(fnUntraced(function* (_, next) {
|
|
92262
|
+
const verifier = encode$3(yield* random.randomBytes(32));
|
|
92263
|
+
const state = encode$3(yield* random.randomBytes(16));
|
|
92264
|
+
const authorize = new URL(AUTHORIZE_PATH, issuer);
|
|
92265
|
+
authorize.search = `${new URLSearchParams({
|
|
92266
|
+
client_id: yield* clientId,
|
|
92267
|
+
code_challenge: encode$3(yield* digest.digest(sha256, new TextEncoder().encode(verifier))),
|
|
92268
|
+
code_challenge_method: "S256",
|
|
92269
|
+
redirect_uri: callback,
|
|
92270
|
+
response_type: "code",
|
|
92271
|
+
scope: "deslop offline_access",
|
|
92272
|
+
state
|
|
92273
|
+
})}`;
|
|
92274
|
+
return setCookieUnsafe(redirect(authorize.href), SIGN_IN_COOKIE, yield* encodeEffect(SignInState)({
|
|
92275
|
+
next: next.href,
|
|
92276
|
+
state,
|
|
92277
|
+
verifier
|
|
92278
|
+
}), {
|
|
92279
|
+
...COOKIE,
|
|
92280
|
+
maxAge: "10 minutes"
|
|
92281
|
+
});
|
|
92282
|
+
})));
|
|
92283
|
+
yield* router.add("GET", CALLBACK_PATH, gen(function* () {
|
|
92284
|
+
const request = yield* HttpServerRequest;
|
|
92285
|
+
return yield* match$8(yield* option$1(decodeUnknownEffect(SignInState)(request.cookies[SIGN_IN_COOKIE])), {
|
|
92286
|
+
onNone: () => signedOut(canonical, "The sign-in expired or began in another browser"),
|
|
92287
|
+
onSome: fnUntraced(function* (saved) {
|
|
92288
|
+
const started = yield* result$1(gen(function* () {
|
|
92289
|
+
const params = yield* schemaSearchParams(CallbackParams$1);
|
|
92290
|
+
if (params.state !== saved.state) return yield* AuthError.make({ message: "The sign-in began in another browser" });
|
|
92291
|
+
if (params.error !== void 0 || params.code === void 0) return yield* AuthError.make({ message: `Auth answered ${params.error ?? "without a code"}` });
|
|
92292
|
+
if (params.iss !== new URL("/api/auth", issuer).href) return yield* AuthError.make({ message: "The answer came from another issuer" });
|
|
92293
|
+
return yield* sessions.start({
|
|
92294
|
+
client_id: yield* clientId,
|
|
92295
|
+
code: params.code,
|
|
92296
|
+
code_verifier: saved.verifier,
|
|
92297
|
+
redirect_uri: callback
|
|
92298
|
+
});
|
|
92299
|
+
}));
|
|
92300
|
+
if (isFailure$1(started)) return yield* signedOut(saved.next, started.failure);
|
|
92301
|
+
return pipe(redirect(saved.next), expireCookieUnsafe(SIGN_IN_COOKIE, COOKIE), setCookieUnsafe(SESSION_COOKIE, started.success, {
|
|
92302
|
+
...COOKIE,
|
|
92303
|
+
maxAge: "365 days"
|
|
92304
|
+
}));
|
|
92305
|
+
})
|
|
92306
|
+
});
|
|
92307
|
+
}));
|
|
92308
|
+
yield* router.add("POST", "/auth/session", gen(function* () {
|
|
92309
|
+
const started = yield* result$1(pipe(schemaBodyJson(CodeGrant), rejected("The sign-in request is invalid"), flatMap$2(sessions.start)));
|
|
92310
|
+
if (isFailure$1(started)) return text(started.failure.message, failureOptions(started.failure, 400));
|
|
92311
|
+
return yield* schemaJson(SessionHandle)({ session: started.success }, { headers: { "cache-control": "no-store" } });
|
|
92312
|
+
}));
|
|
92313
|
+
yield* router.add("GET", "/auth/sign-out", toNext((request, next) => as(ended(request.headers), expireCookieUnsafe(redirect(`${new URL("/", issuer).href}?${new URLSearchParams({
|
|
92314
|
+
next: next.href,
|
|
92315
|
+
"sign-out": ""
|
|
92316
|
+
})}`), SESSION_COOKIE, COOKIE))));
|
|
92317
|
+
yield* router.add("POST", "/auth/sign-out", as(flatMap$2(HttpServerRequest, (request) => ended(request.headers)), empty({ status: 204 })));
|
|
92318
|
+
}));
|
|
92319
|
+
}
|
|
92320
|
+
const layerSessionRoutes = unwrap$7(gen(function* () {
|
|
92321
|
+
return match$8(yield* option(String$5("AUTH_URL")), {
|
|
92322
|
+
onNone: () => empty$11,
|
|
92323
|
+
onSome: layerSignIn
|
|
92324
|
+
});
|
|
92325
|
+
}));
|
|
92214
92326
|
// ../../packages/runtime/src/cli/schema.ts
|
|
92215
92327
|
var AppError = class extends TaggedError()("AppError", {
|
|
92216
92328
|
cause: optional$8(Defect()),
|
|
@@ -92586,10 +92698,10 @@ const SessionVia = Literals([
|
|
|
92586
92698
|
"GitHub",
|
|
92587
92699
|
"Passkey"
|
|
92588
92700
|
]);
|
|
92701
|
+
const StoredOrigin = Struct({ address: optionalKey(String$6) });
|
|
92589
92702
|
const Grants = Record$1(String$6, Struct({
|
|
92590
92703
|
...CredentialOwner.fields,
|
|
92591
92704
|
client: String$6,
|
|
92592
|
-
createdAt: Finite,
|
|
92593
92705
|
credential: TaggedUnion({
|
|
92594
92706
|
App: {
|
|
92595
92707
|
clientId: NonEmptyString,
|
|
@@ -92606,21 +92718,18 @@ const Grants = Record$1(String$6, Struct({
|
|
|
92606
92718
|
}),
|
|
92607
92719
|
device: String$6,
|
|
92608
92720
|
lastActive: Finite,
|
|
92609
|
-
origin:
|
|
92721
|
+
origin: StoredOrigin,
|
|
92610
92722
|
parent: optionalKey(NonEmptyString)
|
|
92611
92723
|
}));
|
|
92612
92724
|
const SignedInApp = Struct({
|
|
92613
92725
|
address: optionalKey(String$6),
|
|
92614
92726
|
client: String$6,
|
|
92615
|
-
createdAt: Finite,
|
|
92616
92727
|
device: String$6,
|
|
92617
|
-
expiresAt: Finite,
|
|
92618
92728
|
family: NonEmptyString,
|
|
92619
92729
|
kind: Literals(["App", "Browser"]),
|
|
92620
92730
|
lastActive: Finite,
|
|
92621
92731
|
parent: optionalKey(NonEmptyString)
|
|
92622
92732
|
});
|
|
92623
|
-
const FamilyParams = Struct({ family: NonEmptyString });
|
|
92624
92733
|
const RevokeParams = Struct({
|
|
92625
92734
|
client_id: NonEmptyString,
|
|
92626
92735
|
token: NonEmptyString
|
|
@@ -92662,7 +92771,195 @@ const AdmitParams = Struct({
|
|
|
92662
92771
|
allow: Boolean$5,
|
|
92663
92772
|
id: NonEmptyString
|
|
92664
92773
|
});
|
|
92665
|
-
|
|
92774
|
+
// src/services/tokens/lib/utils.ts
|
|
92775
|
+
const WORKERS = {
|
|
92776
|
+
"77.237.236.132": "dev",
|
|
92777
|
+
"100.68.201.107": "dev",
|
|
92778
|
+
"100.97.120.3": "desktop",
|
|
92779
|
+
"100.115.207.60": "macbook-pro"
|
|
92780
|
+
};
|
|
92781
|
+
function browserToken(headers) {
|
|
92782
|
+
return parseHeader(headers["cookie"] ?? "")["__Host-session"] ?? "";
|
|
92783
|
+
}
|
|
92784
|
+
function sameOwner(left, right) {
|
|
92785
|
+
return left.user.id === right.user.id && left.incarnation === right.incarnation;
|
|
92786
|
+
}
|
|
92787
|
+
function storedOrigin(origin) {
|
|
92788
|
+
return match$8(fromUndefinedOr(origin.address), {
|
|
92789
|
+
onNone: () => ({}),
|
|
92790
|
+
onSome: (address) => ({ address })
|
|
92791
|
+
});
|
|
92792
|
+
}
|
|
92793
|
+
function randomTokenOf(random) {
|
|
92794
|
+
return (bytes) => map$5(random.randomBytes(bytes), encode$3);
|
|
92795
|
+
}
|
|
92796
|
+
function hashOf(digest) {
|
|
92797
|
+
return (value) => map$5(digest.digest(sha256, new TextEncoder().encode(value)), encode$3);
|
|
92798
|
+
}
|
|
92799
|
+
function live$1(grants, now) {
|
|
92800
|
+
const current = filter$7(grants, (grant) => grant.credential.expiresAt > now);
|
|
92801
|
+
return filter$7(current, (grant) => grant.parent === void 0 || exists(get$13(current, grant.parent), (parent) => parent.credential._tag === "Browser"));
|
|
92802
|
+
}
|
|
92803
|
+
function signedInApps(grants, now, owner) {
|
|
92804
|
+
return pipe(toEntries(live$1(grants, now)), filter$6((entry) => sameOwner(entry[1], owner)), map$8((entry) => ({
|
|
92805
|
+
client: entry[1].client,
|
|
92806
|
+
device: entry[1].device,
|
|
92807
|
+
family: entry[0],
|
|
92808
|
+
kind: entry[1].credential._tag,
|
|
92809
|
+
lastActive: entry[1].lastActive,
|
|
92810
|
+
...pick(entry[1], ["parent"]),
|
|
92811
|
+
...match$8(fromUndefinedOr(entry[1].origin.address), {
|
|
92812
|
+
onNone: () => ({}),
|
|
92813
|
+
onSome: (address) => ({ address })
|
|
92814
|
+
})
|
|
92815
|
+
})), sort(flip$1(mapInput(Number$6, (app) => app.lastActive))));
|
|
92816
|
+
}
|
|
92817
|
+
function withChildActivity(signIns) {
|
|
92818
|
+
const children = groupBy(filter$6(signIns, (signIn) => signIn.parent !== void 0), (signIn) => signIn.parent ?? "");
|
|
92819
|
+
return map$8(filter$6(signIns, (signIn) => signIn.parent === void 0), (signIn) => {
|
|
92820
|
+
const latest = reduce(getOrElse(get$13(children, signIn.family), () => []), signIn, max$2(mapInput(Number$6, (app) => app.lastActive)));
|
|
92821
|
+
return {
|
|
92822
|
+
...omit(signIn, ["address"]),
|
|
92823
|
+
lastActive: latest.lastActive,
|
|
92824
|
+
...pick(latest, ["address"])
|
|
92825
|
+
};
|
|
92826
|
+
});
|
|
92827
|
+
}
|
|
92828
|
+
function parsedAddress(address) {
|
|
92829
|
+
return pipe(getSuccess(ipFromString(address)), map$11((ip) => {
|
|
92830
|
+
if (isIpv6Address(ip)) return getOrElse(fromIpv4Mapped(ip), () => ip);
|
|
92831
|
+
return ip;
|
|
92832
|
+
}));
|
|
92833
|
+
}
|
|
92834
|
+
function isPrivateOrUniqueLocal(ip) {
|
|
92835
|
+
if (isIpv4Address(ip)) return isPrivate(ip);
|
|
92836
|
+
return isUniqueLocal(ip);
|
|
92837
|
+
}
|
|
92838
|
+
function addressGroup(address) {
|
|
92839
|
+
return match$8(parsedAddress(address), {
|
|
92840
|
+
onNone: () => address,
|
|
92841
|
+
onSome: (ip) => {
|
|
92842
|
+
if (isIpv4Address(ip)) return formatIp(ip);
|
|
92843
|
+
return join$2(map$8(take$3(ipv6ToSegments(ip), 4), (segment) => segment.toString(16)), ":");
|
|
92844
|
+
}
|
|
92845
|
+
});
|
|
92846
|
+
}
|
|
92847
|
+
function clientAddress(headers, remote) {
|
|
92848
|
+
return pipe(get$6(headers, "x-forwarded-for"), flatMap$7((forwarded) => last(split$2(",")(forwarded))), map$11(trim), filter$8(isNonEmpty$1), orElse$3(() => remote));
|
|
92849
|
+
}
|
|
92850
|
+
function originFrom(headers, remote) {
|
|
92851
|
+
return {
|
|
92852
|
+
...match$8(clientAddress(headers, remote), {
|
|
92853
|
+
onNone: () => ({}),
|
|
92854
|
+
onSome: (address) => ({ address })
|
|
92855
|
+
}),
|
|
92856
|
+
...match$8(get$6(headers, "user-agent"), {
|
|
92857
|
+
onNone: () => ({}),
|
|
92858
|
+
onSome: (agent) => ({ userAgent: slice$1(0, 200)(agent) })
|
|
92859
|
+
})
|
|
92860
|
+
};
|
|
92861
|
+
}
|
|
92862
|
+
function clientLabel(name) {
|
|
92863
|
+
return pipe(name, replace(/\s*\([^)]*\)$/u, ""), trim, capitalize, liftPredicate(isNonEmpty$1), getOrElse(() => "Unknown client"));
|
|
92864
|
+
}
|
|
92865
|
+
function platform(userAgent) {
|
|
92866
|
+
if (includes("iPhone")(userAgent)) return some$1("iPhone");
|
|
92867
|
+
if (includes("iPad")(userAgent)) return some$1("iPad");
|
|
92868
|
+
if (includes("CFNetwork/")(userAgent)) return some$1("iPhone");
|
|
92869
|
+
if (includes("Android")(userAgent)) return some$1("Android");
|
|
92870
|
+
if (includes("Macintosh")(userAgent)) return some$1("Mac");
|
|
92871
|
+
if (includes("Windows")(userAgent)) return some$1("Windows");
|
|
92872
|
+
if (includes("Linux")(userAgent)) return some$1("Linux");
|
|
92873
|
+
return none();
|
|
92874
|
+
}
|
|
92875
|
+
function browserLabel(origin) {
|
|
92876
|
+
const agent = origin.userAgent ?? "";
|
|
92877
|
+
if (includes("Edg/")(agent)) return "Edge";
|
|
92878
|
+
if (includes("Firefox/")(agent)) return "Firefox";
|
|
92879
|
+
if (includes("Chrome/")(agent)) return "Chrome";
|
|
92880
|
+
if (includes("Safari/")(agent)) return "Safari";
|
|
92881
|
+
return "Browser";
|
|
92882
|
+
}
|
|
92883
|
+
function deviceLabel(origin) {
|
|
92884
|
+
return pipe(flatMap$7(fromUndefinedOr(origin.address), (address) => {
|
|
92885
|
+
if (exists(parsedAddress(address), (ip) => isLinkLocal(ip) || isLoopback(ip) || isPrivateOrUniqueLocal(ip))) return some$1("dev");
|
|
92886
|
+
return get$13(WORKERS, address);
|
|
92887
|
+
}), orElse$3(() => flatMap$7(fromUndefinedOr(origin.userAgent), platform)), getOrElse(() => origin.address ?? "unknown"));
|
|
92888
|
+
}
|
|
92889
|
+
function loopback(redirect) {
|
|
92890
|
+
return filter$8(getSuccess(fromString(redirect)), (target) => target.protocol === "http:" && contains([
|
|
92891
|
+
"127.0.0.1",
|
|
92892
|
+
"[::1]",
|
|
92893
|
+
"localhost"
|
|
92894
|
+
], target.hostname) && isEmpty$1(target.username) && isEmpty$1(target.password) && isEmpty$1(target.search) && isEmpty$1(target.hash));
|
|
92895
|
+
}
|
|
92896
|
+
function webRedirect(redirect) {
|
|
92897
|
+
return isSome(match$3(/^https:\/\/[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?\.mp281x\.xyz\/auth\/callback$/u)(redirect));
|
|
92898
|
+
}
|
|
92899
|
+
function allowedRedirect(redirect) {
|
|
92900
|
+
return webRedirect(redirect) || isSome(match$3(/^https:\/\/gateway\.mp281x\.xyz\/oauth\/callback\/[a-z0-9][a-z0-9_-]{0,23}$/u)(redirect)) || contains([
|
|
92901
|
+
"stash://auth/callback",
|
|
92902
|
+
"stash-dev://auth/callback",
|
|
92903
|
+
"opm://auth/callback",
|
|
92904
|
+
"opm-dev://auth/callback",
|
|
92905
|
+
"trips://auth/callback",
|
|
92906
|
+
"trips-dev://auth/callback"
|
|
92907
|
+
], redirect) || isSome(loopback(redirect));
|
|
92908
|
+
}
|
|
92909
|
+
function clientOf(clientId) {
|
|
92910
|
+
return pipe(decodeString$2(clientId), getSuccess, flatMap$7(decodeUnknownOption(fromJsonString(ClientInfo))), filter$8((client) => every$1(client.redirects, allowedRedirect)));
|
|
92911
|
+
}
|
|
92912
|
+
function portless(redirect) {
|
|
92913
|
+
return map$11(filter$8(match$3(/^(?<origin>http:\/\/(?:127\.0\.0\.1|\[::1\]|localhost))(?::\d{1,5})?(?<rest>\/.*)?$/u)(redirect), () => isSome(loopback(redirect))), (found) => `${found.groups?.["origin"] ?? ""}${found.groups?.["rest"] ?? ""}`);
|
|
92914
|
+
}
|
|
92915
|
+
function matchingRedirect(client, requested) {
|
|
92916
|
+
return match$8(requested, {
|
|
92917
|
+
onNone: () => filter$8(head(client.redirects), () => client.redirects.length === 1),
|
|
92918
|
+
onSome: (asked) => as$2(findFirst(client.redirects, (redirect) => {
|
|
92919
|
+
if (redirect === asked) return true;
|
|
92920
|
+
return isSome(flatMap$7(portless(redirect), (saved) => filter$8(portless(asked), (target) => target === saved)));
|
|
92921
|
+
}), asked)
|
|
92922
|
+
});
|
|
92923
|
+
}
|
|
92924
|
+
function given(value) {
|
|
92925
|
+
return filter$8(fromUndefinedOr(value), isNonEmpty$1);
|
|
92926
|
+
}
|
|
92927
|
+
const clientRequest = fnUntraced(function* (asked, client, params) {
|
|
92928
|
+
if (isNone(given(params.response_type))) return yield* AuthError.make({ message: "Send response_type=code" });
|
|
92929
|
+
if (params.response_type !== "code") return yield* AuthError.make({
|
|
92930
|
+
error: "unsupported_response_type",
|
|
92931
|
+
message: "Only response_type=code is supported"
|
|
92932
|
+
});
|
|
92933
|
+
if (params.code_challenge === void 0 || params.code_challenge_method !== "S256") return yield* AuthError.make({ message: "Send a PKCE code_challenge with code_challenge_method=S256" });
|
|
92934
|
+
if (!every$1(filter$6(split$2(params.scope ?? "", " "), isNonEmpty$1), (scope) => scope === "deslop" || scope === "offline_access")) return yield* AuthError.make({
|
|
92935
|
+
error: "invalid_scope",
|
|
92936
|
+
message: "Only the deslop scope is supported"
|
|
92937
|
+
});
|
|
92938
|
+
return ClientRequest.make({
|
|
92939
|
+
challenge: params.code_challenge,
|
|
92940
|
+
clientId: asked.client_id,
|
|
92941
|
+
clientName: client.clientName,
|
|
92942
|
+
redirectUri: client.redirectUri,
|
|
92943
|
+
...match$8(given(asked.state), {
|
|
92944
|
+
onNone: () => ({}),
|
|
92945
|
+
onSome: (state) => ({ state })
|
|
92946
|
+
})
|
|
92947
|
+
});
|
|
92948
|
+
});
|
|
92949
|
+
function callbackUrl(request, answer, issuer) {
|
|
92950
|
+
const target = new URL(request.redirectUri);
|
|
92951
|
+
for (const entry of toEntries(answer)) target.searchParams.set(entry[0], entry[1]);
|
|
92952
|
+
map$11(given(request.state), (sent) => target.searchParams.set("state", sent));
|
|
92953
|
+
target.searchParams.set("iss", issuer);
|
|
92954
|
+
return target.href;
|
|
92955
|
+
}
|
|
92956
|
+
function returnable(next, url) {
|
|
92957
|
+
const domain = "mp281x.xyz";
|
|
92958
|
+
return match$6(fromString(next), {
|
|
92959
|
+
onFailure: () => false,
|
|
92960
|
+
onSuccess: (target) => (target.origin === new URL(url).origin || target.protocol === "https:" && (target.hostname === domain || endsWith(`.${domain}`)(target.hostname))) && isEmpty$1(target.username) && isEmpty$1(target.password)
|
|
92961
|
+
});
|
|
92962
|
+
}
|
|
92666
92963
|
// src/services/github/service.ts
|
|
92667
92964
|
const HEADERS = {
|
|
92668
92965
|
accept: "application/vnd.github+json",
|
|
@@ -92675,13 +92972,12 @@ const DEVELOPER_PROFILE = GitHubUser.make({
|
|
|
92675
92972
|
});
|
|
92676
92973
|
var GitHub = class GitHub extends Service$1()("@deslop/auth/services/github/service/GitHub") {
|
|
92677
92974
|
static layer = effect(GitHub, gen(function* () {
|
|
92678
|
-
const random = yield* SecureRandom;
|
|
92679
92975
|
const flows = yield* make$22({
|
|
92680
92976
|
capacity: 256,
|
|
92681
92977
|
lookup: () => fail$8(AuthError.make({ message: "The sign-in expired" })),
|
|
92682
92978
|
timeToLive: "10 minutes"
|
|
92683
92979
|
});
|
|
92684
|
-
const nonce =
|
|
92980
|
+
const nonce = randomTokenOf(yield* SecureRandom)(32);
|
|
92685
92981
|
const take = fnUntraced(function* (state) {
|
|
92686
92982
|
const flow = yield* get$2(flows, state);
|
|
92687
92983
|
yield* invalidate(flows, state);
|
|
@@ -92712,7 +93008,7 @@ var GitHub = class GitHub extends Service$1()("@deslop/auth/services/github/serv
|
|
|
92712
93008
|
})
|
|
92713
93009
|
});
|
|
92714
93010
|
const client = filterStatusOk(yield* HttpClient);
|
|
92715
|
-
const
|
|
93011
|
+
const hash = hashOf(yield* Digest);
|
|
92716
93012
|
const provider = yield* all({
|
|
92717
93013
|
clientId: String$5("GITHUB_CLIENT_ID"),
|
|
92718
93014
|
secret: Redacted("GITHUB_CLIENT_SECRET")
|
|
@@ -92749,7 +93045,7 @@ var GitHub = class GitHub extends Service$1()("@deslop/auth/services/github/serv
|
|
|
92749
93045
|
const url = new URL("https://github.com/login/oauth/authorize");
|
|
92750
93046
|
url.search = toString$1(fromInput({
|
|
92751
93047
|
client_id: provider.clientId,
|
|
92752
|
-
code_challenge:
|
|
93048
|
+
code_challenge: yield* hash(verifier),
|
|
92753
93049
|
code_challenge_method: "S256",
|
|
92754
93050
|
redirect_uri: CALLBACK,
|
|
92755
93051
|
state
|
|
@@ -92855,18 +93151,14 @@ const StoredPasskeys = ArraySchema(Struct({
|
|
|
92855
93151
|
...StoredOwner.fields,
|
|
92856
93152
|
addedFrom: String$6,
|
|
92857
93153
|
counter: Int$1,
|
|
92858
|
-
createdAt: Finite,
|
|
92859
93154
|
id: NonEmptyString,
|
|
92860
|
-
lastUsed: Finite,
|
|
92861
93155
|
publicKey: NonEmptyString,
|
|
92862
93156
|
synced: Boolean$5,
|
|
92863
93157
|
transports: ArraySchema(Transport)
|
|
92864
93158
|
}));
|
|
92865
93159
|
const Passkey = Struct({
|
|
92866
93160
|
addedFrom: String$6,
|
|
92867
|
-
createdAt: Finite,
|
|
92868
93161
|
id: NonEmptyString,
|
|
92869
|
-
lastUsed: Finite,
|
|
92870
93162
|
synced: Boolean$5
|
|
92871
93163
|
});
|
|
92872
93164
|
const PasskeyParams = Struct({ id: NonEmptyString });
|
|
@@ -114351,174 +114643,6 @@ async function verifyAuthenticationResponse(options) {
|
|
|
114351
114643
|
}
|
|
114352
114644
|
};
|
|
114353
114645
|
}
|
|
114354
|
-
// src/services/tokens/lib/utils.ts
|
|
114355
|
-
const WORKERS = {
|
|
114356
|
-
"77.237.236.132": "dev",
|
|
114357
|
-
"100.68.201.107": "dev",
|
|
114358
|
-
"100.97.120.3": "desktop",
|
|
114359
|
-
"100.115.207.60": "macbook-pro"
|
|
114360
|
-
};
|
|
114361
|
-
function browserToken(headers) {
|
|
114362
|
-
return parseHeader(headers["cookie"] ?? "")["__Host-session"] ?? "";
|
|
114363
|
-
}
|
|
114364
|
-
function sameOwner(left, right) {
|
|
114365
|
-
return left.user.id === right.user.id && left.incarnation === right.incarnation;
|
|
114366
|
-
}
|
|
114367
|
-
function live$1(grants, now) {
|
|
114368
|
-
const current = filter$7(grants, (grant) => grant.credential.expiresAt > now);
|
|
114369
|
-
return filter$7(current, (grant) => grant.parent === void 0 || exists(get$13(current, grant.parent), (parent) => parent.credential._tag === "Browser"));
|
|
114370
|
-
}
|
|
114371
|
-
function signedInApps(grants, now, owner) {
|
|
114372
|
-
return pipe(toEntries(live$1(grants, now)), filter$6((entry) => sameOwner(entry[1], owner)), map$8((entry) => ({
|
|
114373
|
-
client: entry[1].client,
|
|
114374
|
-
createdAt: entry[1].createdAt,
|
|
114375
|
-
device: entry[1].device,
|
|
114376
|
-
expiresAt: entry[1].credential.expiresAt,
|
|
114377
|
-
family: entry[0],
|
|
114378
|
-
kind: entry[1].credential._tag,
|
|
114379
|
-
lastActive: entry[1].lastActive,
|
|
114380
|
-
...pick(entry[1], ["parent"]),
|
|
114381
|
-
...match$8(fromUndefinedOr(entry[1].origin.address), {
|
|
114382
|
-
onNone: () => ({}),
|
|
114383
|
-
onSome: (address) => ({ address })
|
|
114384
|
-
})
|
|
114385
|
-
})), sort(flip$1(mapInput(Number$6, (app) => app.lastActive))));
|
|
114386
|
-
}
|
|
114387
|
-
function parsedAddress(address) {
|
|
114388
|
-
return pipe(getSuccess(ipFromString(address)), map$11((ip) => {
|
|
114389
|
-
if (isIpv6Address(ip)) return getOrElse(fromIpv4Mapped(ip), () => ip);
|
|
114390
|
-
return ip;
|
|
114391
|
-
}));
|
|
114392
|
-
}
|
|
114393
|
-
function isPrivateOrUniqueLocal(ip) {
|
|
114394
|
-
if (isIpv4Address(ip)) return isPrivate(ip);
|
|
114395
|
-
return isUniqueLocal(ip);
|
|
114396
|
-
}
|
|
114397
|
-
function addressGroup(address) {
|
|
114398
|
-
return match$8(parsedAddress(address), {
|
|
114399
|
-
onNone: () => address,
|
|
114400
|
-
onSome: (ip) => {
|
|
114401
|
-
if (isIpv4Address(ip)) return formatIp(ip);
|
|
114402
|
-
return join$2(map$8(take$3(ipv6ToSegments(ip), 4), (segment) => segment.toString(16)), ":");
|
|
114403
|
-
}
|
|
114404
|
-
});
|
|
114405
|
-
}
|
|
114406
|
-
function clientAddress(headers, remote) {
|
|
114407
|
-
return pipe(get$6(headers, "x-forwarded-for"), flatMap$7((forwarded) => last(split$2(",")(forwarded))), map$11(trim), filter$8(isNonEmpty$1), orElse$3(() => remote));
|
|
114408
|
-
}
|
|
114409
|
-
function originFrom(headers, remote) {
|
|
114410
|
-
return {
|
|
114411
|
-
...match$8(clientAddress(headers, remote), {
|
|
114412
|
-
onNone: () => ({}),
|
|
114413
|
-
onSome: (address) => ({ address })
|
|
114414
|
-
}),
|
|
114415
|
-
...match$8(get$6(headers, "user-agent"), {
|
|
114416
|
-
onNone: () => ({}),
|
|
114417
|
-
onSome: (agent) => ({ userAgent: slice$1(0, 200)(agent) })
|
|
114418
|
-
})
|
|
114419
|
-
};
|
|
114420
|
-
}
|
|
114421
|
-
function clientLabel(name) {
|
|
114422
|
-
return pipe(name, replace(/\s*\([^)]*\)$/u, ""), trim, capitalize, liftPredicate(isNonEmpty$1), getOrElse(() => "Unknown client"));
|
|
114423
|
-
}
|
|
114424
|
-
function platform(userAgent) {
|
|
114425
|
-
if (includes("iPhone")(userAgent)) return some$1("iPhone");
|
|
114426
|
-
if (includes("iPad")(userAgent)) return some$1("iPad");
|
|
114427
|
-
if (includes("CFNetwork/")(userAgent)) return some$1("iPhone");
|
|
114428
|
-
if (includes("Android")(userAgent)) return some$1("Android");
|
|
114429
|
-
if (includes("Macintosh")(userAgent)) return some$1("Mac");
|
|
114430
|
-
if (includes("Windows")(userAgent)) return some$1("Windows");
|
|
114431
|
-
if (includes("Linux")(userAgent)) return some$1("Linux");
|
|
114432
|
-
return none();
|
|
114433
|
-
}
|
|
114434
|
-
function browserLabel(origin) {
|
|
114435
|
-
const agent = origin.userAgent ?? "";
|
|
114436
|
-
if (includes("Edg/")(agent)) return "Edge";
|
|
114437
|
-
if (includes("Firefox/")(agent)) return "Firefox";
|
|
114438
|
-
if (includes("Chrome/")(agent)) return "Chrome";
|
|
114439
|
-
if (includes("Safari/")(agent)) return "Safari";
|
|
114440
|
-
return "Browser";
|
|
114441
|
-
}
|
|
114442
|
-
function deviceLabel(origin) {
|
|
114443
|
-
return pipe(flatMap$7(fromUndefinedOr(origin.address), (address) => {
|
|
114444
|
-
if (exists(parsedAddress(address), (ip) => isLinkLocal(ip) || isLoopback(ip) || isPrivateOrUniqueLocal(ip))) return some$1("dev");
|
|
114445
|
-
return get$13(WORKERS, address);
|
|
114446
|
-
}), orElse$3(() => flatMap$7(fromUndefinedOr(origin.userAgent), platform)), getOrElse(() => origin.address ?? "unknown"));
|
|
114447
|
-
}
|
|
114448
|
-
function loopback(redirect) {
|
|
114449
|
-
return filter$8(getSuccess(fromString(redirect)), (target) => target.protocol === "http:" && contains([
|
|
114450
|
-
"127.0.0.1",
|
|
114451
|
-
"[::1]",
|
|
114452
|
-
"localhost"
|
|
114453
|
-
], target.hostname) && isEmpty$1(target.username) && isEmpty$1(target.password) && isEmpty$1(target.search) && isEmpty$1(target.hash));
|
|
114454
|
-
}
|
|
114455
|
-
function webRedirect(redirect) {
|
|
114456
|
-
return isSome(match$3(/^https:\/\/[a-z\d](?:[a-z\d-]{0,61}[a-z\d])?\.mp281x\.xyz\/auth\/callback$/u)(redirect));
|
|
114457
|
-
}
|
|
114458
|
-
function allowedRedirect(redirect) {
|
|
114459
|
-
return webRedirect(redirect) || isSome(match$3(/^https:\/\/gateway\.mp281x\.xyz\/oauth\/callback\/[a-z0-9][a-z0-9_-]{0,23}$/u)(redirect)) || contains([
|
|
114460
|
-
"stash://auth/callback",
|
|
114461
|
-
"stash-dev://auth/callback",
|
|
114462
|
-
"opm://auth/callback",
|
|
114463
|
-
"opm-dev://auth/callback",
|
|
114464
|
-
"trips://auth/callback",
|
|
114465
|
-
"trips-dev://auth/callback"
|
|
114466
|
-
], redirect) || isSome(loopback(redirect));
|
|
114467
|
-
}
|
|
114468
|
-
function clientOf(clientId) {
|
|
114469
|
-
return pipe(decodeString$2(clientId), getSuccess, flatMap$7(decodeUnknownOption(fromJsonString(ClientInfo))), filter$8((client) => every$1(client.redirects, allowedRedirect)));
|
|
114470
|
-
}
|
|
114471
|
-
function portless(redirect) {
|
|
114472
|
-
return map$11(filter$8(match$3(/^(?<origin>http:\/\/(?:127\.0\.0\.1|\[::1\]|localhost))(?::\d{1,5})?(?<rest>\/.*)?$/u)(redirect), () => isSome(loopback(redirect))), (found) => `${found.groups?.["origin"] ?? ""}${found.groups?.["rest"] ?? ""}`);
|
|
114473
|
-
}
|
|
114474
|
-
function matchingRedirect(client, requested) {
|
|
114475
|
-
return match$8(requested, {
|
|
114476
|
-
onNone: () => filter$8(head(client.redirects), () => client.redirects.length === 1),
|
|
114477
|
-
onSome: (asked) => as$2(findFirst(client.redirects, (redirect) => {
|
|
114478
|
-
if (redirect === asked) return true;
|
|
114479
|
-
return isSome(flatMap$7(portless(redirect), (saved) => filter$8(portless(asked), (target) => target === saved)));
|
|
114480
|
-
}), asked)
|
|
114481
|
-
});
|
|
114482
|
-
}
|
|
114483
|
-
function given(value) {
|
|
114484
|
-
return filter$8(fromUndefinedOr(value), isNonEmpty$1);
|
|
114485
|
-
}
|
|
114486
|
-
const clientRequest = fnUntraced(function* (asked, client, params) {
|
|
114487
|
-
if (isNone(given(params.response_type))) return yield* AuthError.make({ message: "Send response_type=code" });
|
|
114488
|
-
if (params.response_type !== "code") return yield* AuthError.make({
|
|
114489
|
-
error: "unsupported_response_type",
|
|
114490
|
-
message: "Only response_type=code is supported"
|
|
114491
|
-
});
|
|
114492
|
-
if (params.code_challenge === void 0 || params.code_challenge_method !== "S256") return yield* AuthError.make({ message: "Send a PKCE code_challenge with code_challenge_method=S256" });
|
|
114493
|
-
if (!every$1(filter$6(split$2(params.scope ?? "", " "), isNonEmpty$1), (scope) => scope === "deslop" || scope === "offline_access")) return yield* AuthError.make({
|
|
114494
|
-
error: "invalid_scope",
|
|
114495
|
-
message: "Only the deslop scope is supported"
|
|
114496
|
-
});
|
|
114497
|
-
return ClientRequest.make({
|
|
114498
|
-
challenge: params.code_challenge,
|
|
114499
|
-
clientId: asked.client_id,
|
|
114500
|
-
clientName: client.clientName,
|
|
114501
|
-
redirectUri: client.redirectUri,
|
|
114502
|
-
...match$8(given(asked.state), {
|
|
114503
|
-
onNone: () => ({}),
|
|
114504
|
-
onSome: (state) => ({ state })
|
|
114505
|
-
})
|
|
114506
|
-
});
|
|
114507
|
-
});
|
|
114508
|
-
function callbackUrl(request, answer, issuer) {
|
|
114509
|
-
const target = new URL(request.redirectUri);
|
|
114510
|
-
for (const entry of toEntries(answer)) target.searchParams.set(entry[0], entry[1]);
|
|
114511
|
-
map$11(given(request.state), (sent) => target.searchParams.set("state", sent));
|
|
114512
|
-
target.searchParams.set("iss", issuer);
|
|
114513
|
-
return target.href;
|
|
114514
|
-
}
|
|
114515
|
-
function returnable(next, url) {
|
|
114516
|
-
const domain = "mp281x.xyz";
|
|
114517
|
-
return match$6(fromString(next), {
|
|
114518
|
-
onFailure: () => false,
|
|
114519
|
-
onSuccess: (target) => (target.origin === new URL(url).origin || target.protocol === "https:" && (target.hostname === domain || endsWith(`.${domain}`)(target.hostname))) && isEmpty$1(target.username) && isEmpty$1(target.password)
|
|
114520
|
-
});
|
|
114521
|
-
}
|
|
114522
114646
|
// src/services/passkeys/service.ts
|
|
114523
114647
|
const LIFETIME = 3e5;
|
|
114524
114648
|
function invalid(cause) {
|
|
@@ -114591,9 +114715,7 @@ var Passkeys = class Passkeys extends Service$1()("@deslop/auth/services/passkey
|
|
|
114591
114715
|
return [...current, {
|
|
114592
114716
|
addedFrom: `${browserLabel(from)} · ${deviceLabel(from)}`,
|
|
114593
114717
|
counter: credential.counter,
|
|
114594
|
-
createdAt: now,
|
|
114595
114718
|
id: credential.id,
|
|
114596
|
-
lastUsed: now,
|
|
114597
114719
|
publicKey: encode$3(credential.publicKey),
|
|
114598
114720
|
synced: verified.registrationInfo.credentialDeviceType === "multiDevice",
|
|
114599
114721
|
transports,
|
|
@@ -114607,9 +114729,7 @@ var Passkeys = class Passkeys extends Service$1()("@deslop/auth/services/passkey
|
|
|
114607
114729
|
}, rejected("Cannot remove the account’s passkeys")),
|
|
114608
114730
|
list: (owner) => map$3(changes(state), (current) => map$8(filter$6(current, (found) => sameOwner(found, owner)), (found) => ({
|
|
114609
114731
|
addedFrom: found.addedFrom,
|
|
114610
|
-
createdAt: found.createdAt,
|
|
114611
114732
|
id: found.id,
|
|
114612
|
-
lastUsed: found.lastUsed,
|
|
114613
114733
|
synced: found.synced
|
|
114614
114734
|
}))),
|
|
114615
114735
|
registration: fn("Passkeys.registration")(function* (owner, via) {
|
|
@@ -114679,8 +114799,7 @@ var Passkeys = class Passkeys extends Service$1()("@deslop/auth/services/passkey
|
|
|
114679
114799
|
if (stored.id !== found.id) return stored;
|
|
114680
114800
|
return {
|
|
114681
114801
|
...stored,
|
|
114682
|
-
counter: max(stored.counter, verified.authenticationInfo.newCounter)
|
|
114683
|
-
lastUsed: now
|
|
114802
|
+
counter: max(stored.counter, verified.authenticationInfo.newCounter)
|
|
114684
114803
|
};
|
|
114685
114804
|
})));
|
|
114686
114805
|
return {
|
|
@@ -114696,7 +114815,6 @@ const SignInKind = Literals(["App", "Browser"]);
|
|
|
114696
114815
|
const PendingAuthorization = Struct({
|
|
114697
114816
|
address: optionalKey(String$6),
|
|
114698
114817
|
clientName: String$6,
|
|
114699
|
-
createdAt: Finite,
|
|
114700
114818
|
device: String$6,
|
|
114701
114819
|
expiresAt: Finite,
|
|
114702
114820
|
id: NonEmptyString,
|
|
@@ -114751,10 +114869,6 @@ var RpcContracts = class extends make$31(make$35("auth.lookup", {
|
|
|
114751
114869
|
error: AuthError,
|
|
114752
114870
|
payload: AdmitParams,
|
|
114753
114871
|
success: Person
|
|
114754
|
-
}), make$35("auth.remove", {
|
|
114755
|
-
error: AuthError,
|
|
114756
|
-
payload: PersonParams,
|
|
114757
|
-
success: Person
|
|
114758
114872
|
}), make$35("auth.apps", {
|
|
114759
114873
|
error: AuthError,
|
|
114760
114874
|
stream: true,
|
|
@@ -114763,9 +114877,6 @@ var RpcContracts = class extends make$31(make$35("auth.lookup", {
|
|
|
114763
114877
|
error: AuthError,
|
|
114764
114878
|
stream: true,
|
|
114765
114879
|
success: Catalog
|
|
114766
|
-
}), make$35("auth.disconnect", {
|
|
114767
|
-
error: AuthError,
|
|
114768
|
-
payload: FamilyParams
|
|
114769
114880
|
}), make$35("auth.passkeys", {
|
|
114770
114881
|
error: AuthError,
|
|
114771
114882
|
stream: true,
|
|
@@ -114791,9 +114902,9 @@ var RpcContracts = class extends make$31(make$35("auth.lookup", {
|
|
|
114791
114902
|
}))) {};
|
|
114792
114903
|
// src/services/people/lib/utils.ts
|
|
114793
114904
|
const ROLE_ORDER = {
|
|
114794
|
-
Admin:
|
|
114905
|
+
Admin: 1,
|
|
114795
114906
|
Member: 2,
|
|
114796
|
-
Waiting:
|
|
114907
|
+
Waiting: 0
|
|
114797
114908
|
};
|
|
114798
114909
|
function ownerOf(row) {
|
|
114799
114910
|
return {
|
|
@@ -114897,6 +115008,21 @@ function parts(token) {
|
|
|
114897
115008
|
function end(grants, family) {
|
|
114898
115009
|
return filter$7(grants, (grant, key) => key !== family && grant.parent !== family);
|
|
114899
115010
|
}
|
|
115011
|
+
function touch(current, family, now) {
|
|
115012
|
+
return match$8(get$13(current, family), {
|
|
115013
|
+
onNone: () => current,
|
|
115014
|
+
onSome: (grant) => match$1(now - grant.lastActive > 6e4, {
|
|
115015
|
+
onFalse: () => current,
|
|
115016
|
+
onTrue: () => ({
|
|
115017
|
+
...current,
|
|
115018
|
+
[family]: {
|
|
115019
|
+
...grant,
|
|
115020
|
+
lastActive: now
|
|
115021
|
+
}
|
|
115022
|
+
})
|
|
115023
|
+
})
|
|
115024
|
+
});
|
|
115025
|
+
}
|
|
114900
115026
|
var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/service/Tokens") {
|
|
114901
115027
|
static layer = effect(Tokens, gen(function* () {
|
|
114902
115028
|
const storage = yield* KeyValueStore;
|
|
@@ -114920,14 +115046,8 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
114920
115046
|
const signature = yield* Signature;
|
|
114921
115047
|
const codes = yield* make$58(empty$4());
|
|
114922
115048
|
const redeeming = yield* make$71(1);
|
|
114923
|
-
const
|
|
114924
|
-
const
|
|
114925
|
-
function secret(bytes) {
|
|
114926
|
-
return map$5(random.randomBytes(bytes), encode$3);
|
|
114927
|
-
}
|
|
114928
|
-
const hash = fnUntraced(function* (value) {
|
|
114929
|
-
return encode$3(yield* digest.digest(sha256, new TextEncoder().encode(value)));
|
|
114930
|
-
});
|
|
115049
|
+
const randomToken = randomTokenOf(yield* SecureRandom);
|
|
115050
|
+
const hash = hashOf(yield* Digest);
|
|
114931
115051
|
const change = fnUntraced(function* (update) {
|
|
114932
115052
|
return yield* modifyEffect(grants, (current) => gen(function* () {
|
|
114933
115053
|
const now = yield* currentTimeMillis;
|
|
@@ -114978,19 +115098,7 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
114978
115098
|
grant: signedIn,
|
|
114979
115099
|
now
|
|
114980
115100
|
};
|
|
114981
|
-
if (found.now - found.grant.lastActive > 6e4) yield* pipe(change((current) => succeed$5([void 0,
|
|
114982
|
-
onNone: () => current,
|
|
114983
|
-
onSome: (grant) => match$1(found.now - grant.lastActive > 6e4, {
|
|
114984
|
-
onFalse: () => current,
|
|
114985
|
-
onTrue: () => ({
|
|
114986
|
-
...current,
|
|
114987
|
-
[found.family]: {
|
|
114988
|
-
...grant,
|
|
114989
|
-
lastActive: found.now
|
|
114990
|
-
}
|
|
114991
|
-
})
|
|
114992
|
-
})
|
|
114993
|
-
})])), ignore$1({
|
|
115101
|
+
if (found.now - found.grant.lastActive > 6e4) yield* pipe(change((current) => succeed$5([void 0, touch(current, found.family, found.now)])), ignore$1({
|
|
114994
115102
|
log: "Warn",
|
|
114995
115103
|
message: "The token’s last use could not be saved"
|
|
114996
115104
|
}));
|
|
@@ -115000,7 +115108,7 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
115000
115108
|
};
|
|
115001
115109
|
}, rejected("Sign in first"));
|
|
115002
115110
|
const mint = fnUntraced(function* (family, generation, owner, client, now) {
|
|
115003
|
-
const refreshSecret = yield*
|
|
115111
|
+
const refreshSecret = yield* randomToken(32);
|
|
115004
115112
|
const iat = Math.floor(now / 1e3);
|
|
115005
115113
|
const access = yield* provideService(sign(AccessClaims, {
|
|
115006
115114
|
aud: "deslop",
|
|
@@ -115033,7 +115141,6 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
115033
115141
|
const minted = yield* pipe(mint(family, 0, owner, clientLabel(request.clientName), now), rejected("Cannot sign the access token"));
|
|
115034
115142
|
const grant = {
|
|
115035
115143
|
client: clientLabel(request.clientName),
|
|
115036
|
-
createdAt: now,
|
|
115037
115144
|
credential: {
|
|
115038
115145
|
_tag: "App",
|
|
115039
115146
|
clientId: request.clientId,
|
|
@@ -115043,7 +115150,7 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
115043
115150
|
},
|
|
115044
115151
|
device: deviceLabel(origin),
|
|
115045
115152
|
lastActive: now,
|
|
115046
|
-
origin,
|
|
115153
|
+
origin: storedOrigin(origin),
|
|
115047
115154
|
...pick(request, ["parent"]),
|
|
115048
115155
|
...owner
|
|
115049
115156
|
};
|
|
@@ -115056,7 +115163,7 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
115056
115163
|
const redeem = fnUntraced(function* (params, origin, allowed) {
|
|
115057
115164
|
const key = yield* hash(params.code);
|
|
115058
115165
|
const verifier = yield* hash(params.code_verifier);
|
|
115059
|
-
const family = yield*
|
|
115166
|
+
const family = yield* randomToken(16);
|
|
115060
115167
|
const result = yield* change((current, now) => gen(function* () {
|
|
115061
115168
|
const code = yield* pipe(get$4(yield* get$7(codes), key), filter$8((entry) => entry.expiresAt > now), fromOption, mapError$2(() => expired$1));
|
|
115062
115169
|
if (code.state._tag === "Used") return [Exchange.cases.Replayed.make({ message: "This authorization code was already used, so the tokens it gave are revoked; sign in again" }), remove$6(current, code.state.family)];
|
|
@@ -115105,7 +115212,7 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
115105
115212
|
},
|
|
115106
115213
|
device: deviceLabel(origin),
|
|
115107
115214
|
lastActive: now,
|
|
115108
|
-
origin
|
|
115215
|
+
origin: storedOrigin(origin)
|
|
115109
115216
|
}
|
|
115110
115217
|
}];
|
|
115111
115218
|
}));
|
|
@@ -115133,7 +115240,7 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
115133
115240
|
};
|
|
115134
115241
|
}),
|
|
115135
115242
|
device: fn("Tokens.device")(function* (request, owner, origin) {
|
|
115136
|
-
const family = yield*
|
|
115243
|
+
const family = yield* randomToken(16);
|
|
115137
115244
|
return yield* change((current, now) => signIn(current, now, family, request, owner, origin));
|
|
115138
115245
|
}, rejected("Cannot sign the command in")),
|
|
115139
115246
|
disconnect: fn("Tokens.disconnect")(function* (family, owner) {
|
|
@@ -115157,7 +115264,7 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
115157
115264
|
yield* update$3(codes, filter((entry) => entry.state._tag === "Used" || !sameOwner(entry.state.owner, owner)));
|
|
115158
115265
|
}, rejected("Cannot sign this account out")),
|
|
115159
115266
|
issue: fn("Tokens.issue")(function* (request, owner) {
|
|
115160
|
-
const code = yield*
|
|
115267
|
+
const code = yield* randomToken(32);
|
|
115161
115268
|
const key = yield* hash(code);
|
|
115162
115269
|
const now = yield* currentTimeMillis;
|
|
115163
115270
|
yield* update$3(codes, (current) => set$1(filter(current, (entry) => entry.expiresAt > now), key, {
|
|
@@ -115187,8 +115294,8 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
115187
115294
|
session,
|
|
115188
115295
|
sessionVia,
|
|
115189
115296
|
startSession: fn("Tokens.startSession")(function* (owner, origin, via, previousToken) {
|
|
115190
|
-
const family = yield*
|
|
115191
|
-
const sessionSecret = yield*
|
|
115297
|
+
const family = yield* randomToken(16);
|
|
115298
|
+
const sessionSecret = yield* randomToken(32);
|
|
115192
115299
|
const seconds = pipe(value(via), when("Code", () => 2592e3), when("GitHub", () => 31536e3), when("Passkey", () => 31536e3), exhaustive);
|
|
115193
115300
|
const sessionHash = yield* hash(sessionSecret);
|
|
115194
115301
|
const previous = yield* transposeOption(map$11(parts(previousToken), (prior) => map$5(hash(prior.secret), (presented) => ({
|
|
@@ -115207,7 +115314,6 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
115207
115314
|
...retained,
|
|
115208
115315
|
[family]: {
|
|
115209
115316
|
client: browserLabel(origin),
|
|
115210
|
-
createdAt: now,
|
|
115211
115317
|
credential: {
|
|
115212
115318
|
_tag: "Browser",
|
|
115213
115319
|
expiresAt: now + seconds * 1e3,
|
|
@@ -115216,7 +115322,7 @@ var Tokens = class Tokens extends Service$1()("@deslop/auth/services/tokens/serv
|
|
|
115216
115322
|
},
|
|
115217
115323
|
device: deviceLabel(origin),
|
|
115218
115324
|
lastActive: now,
|
|
115219
|
-
origin,
|
|
115325
|
+
origin: storedOrigin(origin),
|
|
115220
115326
|
...owner
|
|
115221
115327
|
}
|
|
115222
115328
|
}]);
|
|
@@ -115242,8 +115348,8 @@ var People = class People extends Service$1()("@deslop/auth/services/people/serv
|
|
|
115242
115348
|
const passkeys = yield* Passkeys;
|
|
115243
115349
|
const github = yield* GitHub;
|
|
115244
115350
|
const admins = yield* adminIds;
|
|
115245
|
-
const random = yield* SecureRandom;
|
|
115246
115351
|
const local = yield* localAuth;
|
|
115352
|
+
const randomToken = randomTokenOf(yield* SecureRandom);
|
|
115247
115353
|
const developer = {
|
|
115248
115354
|
incarnation: "local",
|
|
115249
115355
|
user: DEVELOPER
|
|
@@ -115344,7 +115450,7 @@ var People = class People extends Service$1()("@deslop/auth/services/people/serv
|
|
|
115344
115450
|
return registerMember(current, admins, profile, since, yield* match$8(member(`github:${profile.id}`, current), {
|
|
115345
115451
|
onNone: () => {
|
|
115346
115452
|
if (local && profile.id === 0) return succeed$5("local");
|
|
115347
|
-
return
|
|
115453
|
+
return randomToken(32);
|
|
115348
115454
|
},
|
|
115349
115455
|
onSome: (row) => succeed$5(row.incarnation)
|
|
115350
115456
|
}));
|
|
@@ -115381,6 +115487,7 @@ const layerIssuerAuth = effectContext(gen(function* () {
|
|
|
115381
115487
|
}));
|
|
115382
115488
|
// src/services/sign-ins/lib/utils.ts
|
|
115383
115489
|
const CODE_LETTERS = "BCDFGHJKLMNPQRSTVWXZ";
|
|
115490
|
+
const SIGN_IN_LIFETIME = minutes(10);
|
|
115384
115491
|
function typedCode(text) {
|
|
115385
115492
|
return toUpperCase(replaceAll(/[^a-z]/giu, "")(text));
|
|
115386
115493
|
}
|
|
@@ -122649,7 +122756,7 @@ const start = start$1;
|
|
|
122649
122756
|
// src/services/sign-ins/service.ts
|
|
122650
122757
|
const REQUEST_COOKIE = "__Host-request-";
|
|
122651
122758
|
const expired = AuthError.make({ message: "This sign-in expired. Start it again in the app." });
|
|
122652
|
-
const notWaiting = AuthError.make({ message:
|
|
122759
|
+
const notWaiting = AuthError.make({ message: `No waiting sign-in has this code: it is mistyped, already answered or expired after ${toMinutes(SIGN_IN_LIFETIME)} minutes. Read the code again from the page or command that is still waiting; start a new sign-in only if none is.` });
|
|
122653
122760
|
const deliver = fnUntraced(function* (input) {
|
|
122654
122761
|
const tokens = yield* Tokens;
|
|
122655
122762
|
const people = yield* People;
|
|
@@ -122710,7 +122817,7 @@ const SignIn = make({
|
|
|
122710
122817
|
}),
|
|
122711
122818
|
input: SignInInput,
|
|
122712
122819
|
root: SignInStates,
|
|
122713
|
-
timers: { lifetime:
|
|
122820
|
+
timers: { lifetime: SIGN_IN_LIFETIME }
|
|
122714
122821
|
}).handle({
|
|
122715
122822
|
initial: {
|
|
122716
122823
|
data: (transition) => transition.input,
|
|
@@ -122781,13 +122888,11 @@ var SignIns = class SignIns extends Service$1()("@deslop/auth/services/sign-ins/
|
|
|
122781
122888
|
const tokens = yield* Tokens;
|
|
122782
122889
|
const people = yield* People;
|
|
122783
122890
|
const random = yield* SecureRandom;
|
|
122784
|
-
const
|
|
122891
|
+
const randomToken = randomTokenOf(random);
|
|
122892
|
+
const hash = hashOf(yield* Digest);
|
|
122785
122893
|
const scope$2 = yield* scope;
|
|
122786
122894
|
const open = yield* make$18(empty$4());
|
|
122787
122895
|
const answering = yield* make$71(1);
|
|
122788
|
-
const hash = fnUntraced(function* (value) {
|
|
122789
|
-
return encode$3(yield* digest.digest(sha256, new TextEncoder().encode(value)));
|
|
122790
|
-
});
|
|
122791
122896
|
function find(code) {
|
|
122792
122897
|
return map$5(get(open), get$4(typedCode(code)));
|
|
122793
122898
|
}
|
|
@@ -122868,7 +122973,7 @@ var SignIns = class SignIns extends Service$1()("@deslop/auth/services/sign-ins/
|
|
|
122868
122973
|
start: fn("SignIns.start")(function* (delivery, origin) {
|
|
122869
122974
|
const code = codeFrom(yield* random.randomBytes(8));
|
|
122870
122975
|
const now = yield* currentTimeMillis;
|
|
122871
|
-
const receiver =
|
|
122976
|
+
const receiver = yield* randomToken(32);
|
|
122872
122977
|
const owned = yield* fork(scope$2);
|
|
122873
122978
|
const ref = yield* pipe(run({
|
|
122874
122979
|
delivery,
|
|
@@ -122897,8 +123002,7 @@ var SignIns = class SignIns extends Service$1()("@deslop/auth/services/sign-ins/
|
|
|
122897
123002
|
kind: "App"
|
|
122898
123003
|
})
|
|
122899
123004
|
}),
|
|
122900
|
-
|
|
122901
|
-
expiresAt: now + 6e5,
|
|
123005
|
+
expiresAt: now + toMillis(SIGN_IN_LIFETIME),
|
|
122902
123006
|
id: code
|
|
122903
123007
|
}),
|
|
122904
123008
|
receiver: yield* hash(receiver),
|
|
@@ -122937,12 +123041,6 @@ var SignIns = class SignIns extends Service$1()("@deslop/auth/services/sign-ins/
|
|
|
122937
123041
|
}));
|
|
122938
123042
|
};
|
|
122939
123043
|
// src/http/handlers.ts
|
|
122940
|
-
const COOKIE = {
|
|
122941
|
-
httpOnly: true,
|
|
122942
|
-
path: "/",
|
|
122943
|
-
sameSite: "lax",
|
|
122944
|
-
secure: true
|
|
122945
|
-
};
|
|
122946
123044
|
const LOGIN_COOKIE = "__Host-login";
|
|
122947
123045
|
function session(seconds) {
|
|
122948
123046
|
return {
|
|
@@ -123104,7 +123202,7 @@ const HttpHandlers = use((router) => gen(function* () {
|
|
|
123104
123202
|
}, originOf(request));
|
|
123105
123203
|
return jsonUnsafe({
|
|
123106
123204
|
device_code: started.receiver,
|
|
123107
|
-
expires_in:
|
|
123205
|
+
expires_in: toSeconds(SIGN_IN_LIFETIME),
|
|
123108
123206
|
interval: 2,
|
|
123109
123207
|
user_code: started.code,
|
|
123110
123208
|
verification_uri: `${origin}/`,
|
|
@@ -123207,18 +123305,12 @@ const RpcHandlers = RpcContracts.toLayer(gen(function* () {
|
|
|
123207
123305
|
}),
|
|
123208
123306
|
"auth.apps": () => unwrap$4(map$5(CurrentOwner, tokens.apps)),
|
|
123209
123307
|
"auth.catalog": () => apps.catalog,
|
|
123210
|
-
"auth.disconnect": fnUntraced(function* (input) {
|
|
123211
|
-
return yield* tokens.disconnect(input.family, yield* CurrentOwner);
|
|
123212
|
-
}),
|
|
123213
123308
|
"auth.lookup": (input) => signIns.lookup(input.code),
|
|
123214
123309
|
"auth.passkeyOptions": fnUntraced(function* (_, options) {
|
|
123215
123310
|
return yield* passkeys.registration(yield* CurrentOwner, yield* tokens.sessionVia(options.headers));
|
|
123216
123311
|
}),
|
|
123217
123312
|
"auth.passkeys": () => unwrap$4(map$5(CurrentOwner, passkeys.list)),
|
|
123218
123313
|
"auth.people": () => unwrap$4(map$5(CurrentUser, people.people)),
|
|
123219
|
-
"auth.remove": fnUntraced(function* (input) {
|
|
123220
|
-
return yield* people.remove(input.id, yield* CurrentUser);
|
|
123221
|
-
}),
|
|
123222
123314
|
"auth.removePasskey": fnUntraced(function* (input) {
|
|
123223
123315
|
yield* passkeys.remove(input.id, yield* CurrentOwner);
|
|
123224
123316
|
}),
|
|
@@ -123235,7 +123327,31 @@ const Tools = make$15(make$16("answer_request", {
|
|
|
123235
123327
|
request: NonEmptyString.check(isMaxLength(20))
|
|
123236
123328
|
}),
|
|
123237
123329
|
success: Struct({ clientName: String$6 })
|
|
123238
|
-
}).annotate(Destructive, false)
|
|
123330
|
+
}).annotate(Destructive, false), make$16("list_sessions", {
|
|
123331
|
+
dependencies: [CurrentOwner],
|
|
123332
|
+
description: "Each signed-in client of yours with its id, device, last activity and address; sign one out with sign_out_session.",
|
|
123333
|
+
failure: AuthError,
|
|
123334
|
+
parameters: EmptyParams,
|
|
123335
|
+
success: Struct({ sessions: ArraySchema(Struct({
|
|
123336
|
+
address: optionalKey(String$6),
|
|
123337
|
+
client: String$6,
|
|
123338
|
+
device: String$6,
|
|
123339
|
+
id: NonEmptyString,
|
|
123340
|
+
lastActive: Finite
|
|
123341
|
+
})) })
|
|
123342
|
+
}).annotate(Readonly, true), make$16("sign_out_session", {
|
|
123343
|
+
dependencies: [CurrentOwner],
|
|
123344
|
+
description: "Sign a client out of every app by the id list_sessions returns.",
|
|
123345
|
+
failure: AuthError,
|
|
123346
|
+
parameters: Struct({ id: NonEmptyString }),
|
|
123347
|
+
success: Struct({ id: NonEmptyString })
|
|
123348
|
+
}).annotate(Destructive, true), make$16("remove_person", {
|
|
123349
|
+
dependencies: [CurrentOwner],
|
|
123350
|
+
description: "Remove a member by their GitHub login; admins cannot be removed.",
|
|
123351
|
+
failure: AuthError,
|
|
123352
|
+
parameters: Struct({ login: NonEmptyString }),
|
|
123353
|
+
success: Person
|
|
123354
|
+
}).annotate(Destructive, true));
|
|
123239
123355
|
// src/tools/handlers.ts
|
|
123240
123356
|
const layerMcpOwner = unwrap$7(gen(function* () {
|
|
123241
123357
|
const tokens = yield* Tokens;
|
|
@@ -123256,13 +123372,38 @@ const layerMcpOwner = unwrap$7(gen(function* () {
|
|
|
123256
123372
|
})), (owner) => provideService(effect, CurrentOwner, owner))).layer;
|
|
123257
123373
|
}));
|
|
123258
123374
|
const ToolHandlers = Tools.toLayer(gen(function* () {
|
|
123375
|
+
const people = yield* People;
|
|
123259
123376
|
const signIns = yield* SignIns;
|
|
123260
|
-
|
|
123261
|
-
|
|
123262
|
-
|
|
123377
|
+
const tokens = yield* Tokens;
|
|
123378
|
+
return Tools.of({
|
|
123379
|
+
answer_request: fnUntraced(function* (input) {
|
|
123380
|
+
return yield* signIns.answer(input, yield* CurrentOwner, "Token");
|
|
123381
|
+
}),
|
|
123382
|
+
list_sessions: fnUntraced(function* () {
|
|
123383
|
+
return { sessions: map$8(withChildActivity(getOrElse(yield* runHead(tokens.apps(yield* CurrentOwner)), () => [])), (app) => ({
|
|
123384
|
+
...pick(app, [
|
|
123385
|
+
"address",
|
|
123386
|
+
"client",
|
|
123387
|
+
"device",
|
|
123388
|
+
"lastActive"
|
|
123389
|
+
]),
|
|
123390
|
+
id: app.family
|
|
123391
|
+
})) };
|
|
123392
|
+
}),
|
|
123393
|
+
remove_person: fnUntraced(function* (input) {
|
|
123394
|
+
const owner = yield* CurrentOwner;
|
|
123395
|
+
const wanted = toLowerCase(input.login);
|
|
123396
|
+
const person = yield* pipe(yield* people.list(owner.user), findFirst((row) => toLowerCase(row.name) === wanted), fromOption, mapError$2(() => AuthError.make({ message: `No GitHub account ${input.login} is listed in Auth` })));
|
|
123397
|
+
return yield* people.remove(person.id, owner.user);
|
|
123398
|
+
}),
|
|
123399
|
+
sign_out_session: fnUntraced(function* (input) {
|
|
123400
|
+
yield* tokens.disconnect(input.id, yield* CurrentOwner);
|
|
123401
|
+
return { id: input.id };
|
|
123402
|
+
})
|
|
123403
|
+
});
|
|
123263
123404
|
}));
|
|
123264
123405
|
// src/main.server.ts
|
|
123265
|
-
const layerServices = pipe(mergeAll$1(SignIns.layer, layer$2), provideMerge(People.layer), provideMerge(mergeAll$1(Tokens.layer, Passkeys.layer, GitHub.layer, Apps.layer
|
|
123406
|
+
const layerServices = pipe(mergeAll$1(SignIns.layer, provide$2(layer$2, layerStoreMemory)), provideMerge(People.layer), provideMerge(mergeAll$1(Tokens.layer, Passkeys.layer, GitHub.layer, Apps.layer)), provide$2(succeed$6(RequestInit, { redirect: "error" })));
|
|
123266
123407
|
runApp({
|
|
123267
123408
|
auth: provide$2(layerIssuerAuth, layerServices),
|
|
123268
123409
|
icon: icon_default,
|