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

import (
	"net/http"

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

type TokenParser x.Mapper[*http.Request, oidc.RawToken]

func IDTokenFromSessionCookie(r *http.Request) oidc.RawToken {
	cookies := r.CookiesNamed(cfg.IDTokenCookie)

	if len(cookies) != 1 {
		return ""
	}

	return oidc.RawToken(cookies[0].Value)
}