Loading .vscode/settings.json +1 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ "nodeinfo", "phensley", "Pixelfed", "redirections", "rels", "setext", "subproperty", Loading CHANGES.md +7 −1 Original line number Diff line number Diff line Loading @@ -21,9 +21,15 @@ To be released. - Added `getActorHandle()` function. - Now `loookupWebFinger()` follows redirections. - Fedify now has authenticated document loader. [[#12]] - Added `Context.getDocumentLoader()` method. - Added `getAuthenticatedDocumentLoader()` function. - Now `lookupWebFinger()` follows redirections. [Fresh]: https://fresh.deno.dev/ [#12]: https://github.com/dahlia/fedify/issues/12 Version 0.3.0 Loading docs/manual/context.md +19 −0 Original line number Diff line number Diff line Loading @@ -153,3 +153,22 @@ So you can just pass a `Context` object to those methods: const object = await Object.fromJsonLd(jsonLd, ctx); const json = await object.toJsonLd(ctx); ~~~~ Getting an authenticated `DocumentLoader` ----------------------------------------- Sometimes you need to load a remote document which requires authentication, such as an actor's following collection that is configured as private. In such cases, you can use the `Context.getDocumentLoader()` method to get an authenticated `DocumentLoader` object. The following shows an example: ~~~~ typescript const documentLoader = await ctx.getDocumentLoader({ handle: "john" }); const following = await actor.getFollowing({ documentLoader }); ~~~~ In the above example, the `getFollowing()` method takes the `documentLoader` which is authenticated as the actor with a handle of `john`. If the `actor` allows `john` to see the following collection, the `getFollowing()` method returns the following collection. docs/manual/vocab.md +16 −0 Original line number Diff line number Diff line Loading @@ -217,6 +217,22 @@ example of looking up a `Note` object from the URI: const note = await lookupObject("https://todon.eu/@hongminhee/112060633798771581"); ~~~~ > [!NOTE] > Some objects require authentication to look up, such as a `Note` object with > a visibility of followers-only. In such cases, you need to use > the `Context.getDocumentLoader()` method to get an authenticated > `DocumentLoader` object. The `lookupObject()` function takes the > `documentLoader` option to specify the method to fetch the remote object: > > ~~~~ typescript > const documentLoader = await ctx.getDocumentLoader({ handle: "john" }); > const note = await lookupObject("...", { documentLoader }); > ~~~~ > > See the [*Getting an authenticated > `DocumentLoader`*](./context.md#getting-an-authenticated-documentloader) > section for details. JSON-LD ------- Loading federation/context.ts +27 −1 Original line number Diff line number Diff line Loading @@ -84,12 +84,38 @@ export interface Context<TContextData> { */ getActorKey(handle: string): Promise<CryptographicKey | null>; /** * Gets an authenticated {@link DocumentLoader} for the given identity. * Note that an authenticated document loader intentionally does not cache * the fetched documents. * @param identity The identity to get the document loader for. * The actor's handle. * @returns The authenticated document loader. * @throws {Error} If the identity is not valid. * @throws {TypeError} If the key is invalid or unsupported. */ getDocumentLoader(identity: { handle: string }): Promise<DocumentLoader>; /** * Gets an authenticated {@link DocumentLoader} for the given identity. * Note that an authenticated document loader intentionally does not cache * the fetched documents. * @param identity The identity to get the document loader for. * The actor's key pair. * @returns The authenticated document loader. * @throws {TypeError} If the key is invalid or unsupported. */ getDocumentLoader( identity: { keyId: URL; privateKey: CryptoKey }, ): DocumentLoader; /** * Sends an activity to recipients' inboxes. * @param sender The sender's handle or sender's key pair. * @param sender The sender's handle or the sender's key pair. * @param recipients The recipients of the activity. * @param activity The activity to send. * @param options Options for sending the activity. * @throws {Error} If the sender is not valid. */ sendActivity( sender: { keyId: URL; privateKey: CryptoKey } | { handle: string }, Loading Loading
.vscode/settings.json +1 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ "nodeinfo", "phensley", "Pixelfed", "redirections", "rels", "setext", "subproperty", Loading
CHANGES.md +7 −1 Original line number Diff line number Diff line Loading @@ -21,9 +21,15 @@ To be released. - Added `getActorHandle()` function. - Now `loookupWebFinger()` follows redirections. - Fedify now has authenticated document loader. [[#12]] - Added `Context.getDocumentLoader()` method. - Added `getAuthenticatedDocumentLoader()` function. - Now `lookupWebFinger()` follows redirections. [Fresh]: https://fresh.deno.dev/ [#12]: https://github.com/dahlia/fedify/issues/12 Version 0.3.0 Loading
docs/manual/context.md +19 −0 Original line number Diff line number Diff line Loading @@ -153,3 +153,22 @@ So you can just pass a `Context` object to those methods: const object = await Object.fromJsonLd(jsonLd, ctx); const json = await object.toJsonLd(ctx); ~~~~ Getting an authenticated `DocumentLoader` ----------------------------------------- Sometimes you need to load a remote document which requires authentication, such as an actor's following collection that is configured as private. In such cases, you can use the `Context.getDocumentLoader()` method to get an authenticated `DocumentLoader` object. The following shows an example: ~~~~ typescript const documentLoader = await ctx.getDocumentLoader({ handle: "john" }); const following = await actor.getFollowing({ documentLoader }); ~~~~ In the above example, the `getFollowing()` method takes the `documentLoader` which is authenticated as the actor with a handle of `john`. If the `actor` allows `john` to see the following collection, the `getFollowing()` method returns the following collection.
docs/manual/vocab.md +16 −0 Original line number Diff line number Diff line Loading @@ -217,6 +217,22 @@ example of looking up a `Note` object from the URI: const note = await lookupObject("https://todon.eu/@hongminhee/112060633798771581"); ~~~~ > [!NOTE] > Some objects require authentication to look up, such as a `Note` object with > a visibility of followers-only. In such cases, you need to use > the `Context.getDocumentLoader()` method to get an authenticated > `DocumentLoader` object. The `lookupObject()` function takes the > `documentLoader` option to specify the method to fetch the remote object: > > ~~~~ typescript > const documentLoader = await ctx.getDocumentLoader({ handle: "john" }); > const note = await lookupObject("...", { documentLoader }); > ~~~~ > > See the [*Getting an authenticated > `DocumentLoader`*](./context.md#getting-an-authenticated-documentloader) > section for details. JSON-LD ------- Loading
federation/context.ts +27 −1 Original line number Diff line number Diff line Loading @@ -84,12 +84,38 @@ export interface Context<TContextData> { */ getActorKey(handle: string): Promise<CryptographicKey | null>; /** * Gets an authenticated {@link DocumentLoader} for the given identity. * Note that an authenticated document loader intentionally does not cache * the fetched documents. * @param identity The identity to get the document loader for. * The actor's handle. * @returns The authenticated document loader. * @throws {Error} If the identity is not valid. * @throws {TypeError} If the key is invalid or unsupported. */ getDocumentLoader(identity: { handle: string }): Promise<DocumentLoader>; /** * Gets an authenticated {@link DocumentLoader} for the given identity. * Note that an authenticated document loader intentionally does not cache * the fetched documents. * @param identity The identity to get the document loader for. * The actor's key pair. * @returns The authenticated document loader. * @throws {TypeError} If the key is invalid or unsupported. */ getDocumentLoader( identity: { keyId: URL; privateKey: CryptoKey }, ): DocumentLoader; /** * Sends an activity to recipients' inboxes. * @param sender The sender's handle or sender's key pair. * @param sender The sender's handle or the sender's key pair. * @param recipients The recipients of the activity. * @param activity The activity to send. * @param options Options for sending the activity. * @throws {Error} If the sender is not valid. */ sendActivity( sender: { keyId: URL; privateKey: CryptoKey } | { handle: string }, Loading