Commit 6f428ae7 authored by Grant's avatar Grant
Browse files

add authorized fetch (fixes #17)

parent 488b2366
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -29,9 +29,13 @@ export class APub {
    this.ctx = ctx;
  }

  static options: (ctx: Context<void>) => LookupObjectOptions = (ctx) => ({
  static options: (
    ctx: Context<void>,
    opts?: Partial<LookupObjectOptions>
  ) => LookupObjectOptions = (ctx, opts = {}) => ({
    ...ctx,
    allowPrivateAddress: process.env.NODE_ENV === "development",
    ...opts,
  });

  static get accountHandle() {
@@ -40,7 +44,13 @@ export class APub {

  static async sendDM(session: AuthSession) {
    const ctx = federation.createContext(new URL("/", process.env.OIDC_ISSUER));
    const recipient = await lookupObject(session.user_sub, this.options(ctx));
    const documentLoader = await ctx.getDocumentLoader({
      identifier: USER_IDENTIFIER,
    });
    const recipient = await lookupObject(
      session.user_sub,
      this.options(ctx, { documentLoader })
    );

    if (!isActor(recipient)) throw new Error("Not an actor");

@@ -81,7 +91,13 @@ export class APub {

  static async deleteDM(session: AuthSession) {
    const ctx = federation.createContext(new URL("/", process.env.OIDC_ISSUER));
    const recipient = await lookupObject(session.user_sub, this.options(ctx));
    const documentLoader = await ctx.getDocumentLoader({
      identifier: USER_IDENTIFIER,
    });
    const recipient = await lookupObject(
      session.user_sub,
      this.options(ctx, { documentLoader })
    );

    if (!isActor(recipient)) throw new Error("Not an actor");