Compare commits

..

9 Commits

Author SHA1 Message Date
Stavros 5e2b6bc8bf fix: add oidc service to services struct on init 2026-06-15 16:52:16 +03:00
Stavros c3dd056a56 refactor: use loop for dig provide for simpler error handling 2026-06-14 20:13:58 +03:00
Stavros 8426db306d chore: rabbit comments 2026-06-14 18:20:17 +03:00
Stavros 4b323d07ab tests: use new inputs in tests 2026-06-14 18:01:12 +03:00
Stavros 568809a9dc fix: fix gh codeql review 2026-06-14 01:01:45 +03:00
Stavros e4dc3ca2e4 fix: don't use pointers in interfaces 2026-06-14 00:35:18 +03:00
Stavros f8b85e3bc7 feat: use dig for controllers 2026-06-14 00:20:06 +03:00
Stavros 7cd3719734 feat: use dig for all services 2026-06-13 23:20:46 +03:00
Stavros c51ec3c7f6 feat: use dig for di in services 2026-06-13 20:25:18 +03:00
2 changed files with 1 additions and 75 deletions
+1
View File
@@ -57,6 +57,7 @@ func (app *BootstrapApp) setupServices() error {
app.services.authService = i.AuthService
app.services.ldapService = i.LDAPService
app.services.oauthBrokerService = i.OAuthBrokerService
app.services.oidcService = i.OIDCService
app.services.tailscaleService = i.TailscaleService
return nil
})
@@ -3,27 +3,12 @@ package controller
import (
"fmt"
"net/http"
"net/url"
"slices"
"strings"
"github.com/gin-gonic/gin"
"github.com/tinyauthapp/tinyauth/internal/service"
"go.uber.org/dig"
)
const OpenIDConnectRel = "http://openid.net/specs/connect/1.0/issuer"
type WebfingerResponseLink struct {
Rel string `json:"rel,omitempty"`
Href string `json:"href"`
}
type WebfingerResponse struct {
Subject string `json:"subject"`
Links []WebfingerResponseLink `json:"links"`
}
type OpenIDConnectConfiguration struct {
Issuer string `json:"issuer"`
AuthorizationEndpoint string `json:"authorization_endpoint"`
@@ -60,7 +45,6 @@ func NewWellKnownController(i WellKnownControllerInput) *WellKnownController {
i.RouterGroup.GET("/.well-known/openid-configuration", controller.OpenIDConnectConfiguration)
i.RouterGroup.GET("/.well-known/jwks.json", controller.JWKS)
i.RouterGroup.GET("/.well-known/webfinger", controller.WebFinger)
return controller
}
@@ -121,62 +105,3 @@ func (controller *WellKnownController) JWKS(c *gin.Context) {
c.Status(http.StatusOK)
}
func (controller *WellKnownController) WebFinger(c *gin.Context) {
c.Header("Content-Type", "application/jrd+json")
c.Header("Access-Control-Allow-Origin", "*")
resource := c.Query("resource")
if !controller.validateWebFingerResource(resource) {
c.JSON(400, gin.H{
"status": 400,
"message": "invalid resource",
})
return
}
res := WebfingerResponse{
Subject: resource,
Links: []WebfingerResponseLink{},
}
rel := c.Request.URL.Query()["rel"]
if controller.oidc != nil && (len(rel) == 0 || slices.Contains(rel, OpenIDConnectRel)) {
res.Links = append(res.Links, WebfingerResponseLink{Rel: OpenIDConnectRel, Href: controller.oidc.GetIssuer()})
}
c.JSON(200, res)
}
func (controller *WellKnownController) validateWebFingerResource(resource string) bool {
prefix, suffix, found := strings.Cut(resource, ":")
if !found {
return false
}
switch prefix {
case "acct":
if strings.Count(suffix, "@") != 1 {
return false
}
username, domain, found := strings.Cut(suffix, "@")
if !found || username == "" || domain == "" {
return false
}
case "https", "http":
u, err := url.Parse(resource)
if err != nil {
return false
}
if u.Host == "" {
return false
}
default:
return false
}
return true
}