Forward webfinger request

This commit is contained in:
LittleSheep 2025-03-11 21:52:47 +08:00
parent 31f29cf940
commit 7994d1a897
2 changed files with 27 additions and 1 deletions

View File

@ -2,14 +2,39 @@ package api
import (
"fmt"
"strings"
"git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/proxy"
"github.com/spf13/viper"
"github.com/valyala/fasthttp"
"strings"
)
func forwardWebfinger(c *fiber.Ctx) error {
service := directory.GetServiceInstanceByType("co")
if service == nil || service.HttpAddr == nil {
return fiber.ErrNotFound
}
url := c.OriginalURL()
url = strings.Replace(url, "/.well-known", "", 1)
url = *service.HttpAddr + url
if tk, ok := c.Locals("nex_token").(string); ok {
c.Request().Header.Set(fiber.HeaderAuthorization, fmt.Sprintf("Bearer %s", tk))
} else {
c.Request().Header.Del(fiber.HeaderAuthorization)
}
return proxy.Do(c, url, &fasthttp.Client{
NoDefaultUserAgentHeader: true,
DisablePathNormalizing: true,
StreamResponseBody: true,
})
}
func forwardService(c *fiber.Ctx) error {
serviceType := c.Params("service")
ogKeyword := serviceType

View File

@ -26,6 +26,7 @@ func MapControllers(app *fiber.App) {
// Some built-in public-accessible APIs
wellKnown := app.Group("/.well-known").Name("Well Known")
{
wellKnown.Get("/webfinger", forwardWebfinger) // Forward webfinger to Interactive
wellKnown.Get("/openid-configuration", func(c *fiber.Ctx) error {
service := directory.GetServiceInstanceByType(nex.ServiceTypeAuth)
if service == nil || service.HttpAddr == nil {