✨ Forward webfinger request
This commit is contained in:
parent
31f29cf940
commit
7994d1a897
@ -2,14 +2,39 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
|
"git.solsynth.dev/hypernet/nexus/pkg/internal/directory"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/proxy"
|
"github.com/gofiber/fiber/v2/middleware/proxy"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/valyala/fasthttp"
|
"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 {
|
func forwardService(c *fiber.Ctx) error {
|
||||||
serviceType := c.Params("service")
|
serviceType := c.Params("service")
|
||||||
ogKeyword := serviceType
|
ogKeyword := serviceType
|
||||||
|
@ -26,6 +26,7 @@ func MapControllers(app *fiber.App) {
|
|||||||
// Some built-in public-accessible APIs
|
// Some built-in public-accessible APIs
|
||||||
wellKnown := app.Group("/.well-known").Name("Well Known")
|
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 {
|
wellKnown.Get("/openid-configuration", func(c *fiber.Ctx) error {
|
||||||
service := directory.GetServiceInstanceByType(nex.ServiceTypeAuth)
|
service := directory.GetServiceInstanceByType(nex.ServiceTypeAuth)
|
||||||
if service == nil || service.HttpAddr == nil {
|
if service == nil || service.HttpAddr == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user