* poc: service/idp no-js # Conflicts: # services/idp/package.json # Conflicts: # services/idp/package.json # services/idp/pnpm-lock.yaml # Conflicts: # services/idp/package.json # services/idp/pnpm-lock.yaml # Conflicts: # services/idp/package.json # services/idp/pnpm-lock.yaml * poc: service/idp no-js, css theme * poc: service/idp no-js, l10n transifex * poc: service/idp no-js, test * poc: service/idp no-js, security * poc: service/idp no-js, cleanup * poc: service/idp no-js, fix CI * poc: service/idp no-js, css theme * poc: service/idp no-js, changelog * poc: service/idp no-js, fix CI * poc: service/idp no-js, cleanup * poc: service/idp no-js, fix CSP [565] * poc: service/idp no-js, fix CI * poc: service/idp no-js, html.template * poc: service/idp no-js, fix bg image * poc: service/idp no-js, fix consent * poc: service/idp no-js, add consent.html template consent.html was created but not committed; the embed.FS could not find it, causing a fatal at startup in tests and production. * poc: service/idp no-js, login page exact as previous * poc: service/idp no-js, desktop oauth path * poc: service/idp no-js, desktop oauth path * poc: service/idp no-js, desktop oauth path * poc: service/idp no-js, add loginerror template * poc: service/idp no-js, desktop oauth path * poc: service/idp no-js, simplify * poc: service/idp no-js, follow OWASP principles * poc: service/idp no-js, fix ci * poc: service/idp no-js, theme review * poc: service/idp no-js, theme review
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
// Package middleware provides middleware for the idp service.
|
|
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/codes"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// Static is a middleware that serves static assets.
|
|
func Static(root string, fs http.FileSystem, tp trace.TracerProvider) func(http.Handler) http.Handler {
|
|
if !strings.HasSuffix(root, "/") {
|
|
root = root + "/"
|
|
}
|
|
|
|
static := http.StripPrefix(
|
|
root,
|
|
http.FileServer(
|
|
fs,
|
|
),
|
|
)
|
|
|
|
return func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
spanOpts := []trace.SpanStartOption{
|
|
trace.WithSpanKind(trace.SpanKindServer),
|
|
}
|
|
ctx, span := tp.Tracer("idp").Start(r.Context(), "serve static asset", spanOpts...)
|
|
defer span.End()
|
|
r = r.WithContext(ctx)
|
|
|
|
// serve the static assets for the identifier web app
|
|
if strings.HasPrefix(r.URL.Path, "/signin/v1/static/") {
|
|
if strings.HasSuffix(r.URL.Path, "/") {
|
|
// but no listing of folders
|
|
span.SetAttributes(attribute.KeyValue{Key: "path", Value: attribute.StringValue(r.URL.Path)})
|
|
span.SetStatus(codes.Error, "asset not found")
|
|
http.NotFound(w, r)
|
|
} else {
|
|
r.URL.Path = strings.Replace(r.URL.Path, "/signin/v1/static/", "/signin/v1/identifier/static/", 1)
|
|
span.SetAttributes(attribute.KeyValue{Key: "server", Value: attribute.StringValue(r.URL.Path)})
|
|
if strings.HasSuffix(r.URL.Path, ".css") {
|
|
w.Header().Set("Cache-Control", "no-cache")
|
|
}
|
|
static.ServeHTTP(w, r)
|
|
}
|
|
return
|
|
}
|
|
span.SetAttributes(attribute.KeyValue{Key: "path", Value: attribute.StringValue(r.URL.Path)})
|
|
span.SetStatus(codes.Ok, "ok")
|
|
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
}
|