Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
timonson committed May 14, 2024
1 parent 673d88b commit 8db1dc5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
3 changes: 3 additions & 0 deletions functions/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ export {
isUndefined,
isUrl,
} from "https://dev.zaubrik.com/[email protected]/type.js";
export {
type AuthInput,
} from "https://dev.zaubrik.com/[email protected]/server/response.ts";
11 changes: 11 additions & 0 deletions functions/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type AuthInput,
create,
decodeJwt,
isObject,
Expand Down Expand Up @@ -86,6 +87,16 @@ export async function createJwt(
}
}

export function ensureVerifyFunction(authInput: AuthInput) {
const verification = authInput.verification;
return {
...authInput,
verification: typeof verification === "function"
? verification
: verifyJwt(verification),
};
}

export function verifyJwt(input: CryptoKeyOrUpdateInput) {
const cryptoKeyPromiseOrNull = isUpdateInput(input)
? fetchRsaCryptoKey(input.url, input.algorithm)
Expand Down
14 changes: 2 additions & 12 deletions middlewares/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,15 @@ import {
type Options,
respond,
} from "./deps.ts";
import { verifyJwt } from "../functions/jwt.ts";

function addVerifyFunctions(authInput: AuthInput) {
const verification = authInput.verification;
return {
...authInput,
verification: typeof verification === "function"
? verification
: verifyJwt(verification),
};
}
import { ensureVerifyFunction } from "../functions/jwt.ts";

export function rpcRespond(
methods: Methods,
options: Options & { methodsUrl?: URL } = {},
authInput?: AuthInput | AuthInput[],
) {
const authInputArray = authInput
? [authInput].flat().map(addVerifyFunctions)
? [authInput].flat().map(ensureVerifyFunction)
: undefined;
return async <C extends Context>(ctx: C) => {
const rpcMethods = options.methodsUrl
Expand Down

0 comments on commit 8db1dc5

Please sign in to comment.