mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
console/authentication: template logout and avatar URLs if not provided
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
This commit is contained in:
@@ -6,6 +6,8 @@ package authentication
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
@@ -24,6 +26,14 @@ type UserInformation struct {
|
||||
// current user. It does not really perform authentication but relies
|
||||
// on HTTP headers.
|
||||
func (c *Component) UserAuthentication() gin.HandlerFunc {
|
||||
var logoutURLTmpl, avatarURLTmpl *template.Template
|
||||
if c.config.LogoutURL != "" {
|
||||
logoutURLTmpl, _ = template.New("logout").Parse(c.config.LogoutURL)
|
||||
}
|
||||
if c.config.AvatarURL != "" {
|
||||
avatarURLTmpl, _ = template.New("avatar").Parse(c.config.AvatarURL)
|
||||
}
|
||||
|
||||
return func(gc *gin.Context) {
|
||||
var info UserInformation
|
||||
if err := gc.ShouldBindWith(&info, customHeaderBinding{c}); err != nil {
|
||||
@@ -34,6 +44,21 @@ func (c *Component) UserAuthentication() gin.HandlerFunc {
|
||||
}
|
||||
info = c.config.DefaultUser
|
||||
}
|
||||
|
||||
// Apply configured templates (they can access header values and choose to keep or override)
|
||||
if logoutURLTmpl != nil {
|
||||
var buf strings.Builder
|
||||
if err := logoutURLTmpl.Execute(&buf, info); err == nil {
|
||||
info.LogoutURL = buf.String()
|
||||
}
|
||||
}
|
||||
if avatarURLTmpl != nil {
|
||||
var buf strings.Builder
|
||||
if err := avatarURLTmpl.Execute(&buf, info); err == nil {
|
||||
info.AvatarURL = buf.String()
|
||||
}
|
||||
}
|
||||
|
||||
gc.Set("user", info)
|
||||
gc.Next()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user