summaryrefslogtreecommitdiff
path: root/app/middleware/init.go
blob: 23c524dae79e83816c88db345235c059969535df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package middleware

import (
	"net/http"

	"github.com/xlgmokha/x/pkg/mapper"
	"github.com/xlgmokha/x/pkg/x"
	"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app/domain"
)

func init() {
	mapper.Register(func(h http.Header) *domain.User {
		subject := h.Get("x-jwt-claim-sub")
		if x.IsPresent(subject) {
			return &domain.User{
				ID:         domain.ID(h.Get("x-jwt-claim-sub")),
				Username:   h.Get("x-jwt-claim-username"),
				ProfileURL: h.Get("x-jwt-claim-profile-url"),
				Picture:    h.Get("x-jwt-claim-picture-url"),
			}
		}
		return nil
	})
}