-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhistorical_keys.go
More file actions
37 lines (34 loc) · 933 Bytes
/
historical_keys.go
File metadata and controls
37 lines (34 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package lighthouse
import (
"github.com/go-oidfed/lib/jwx"
"github.com/go-oidfed/lib/oidfedconst"
"github.com/go-oidfed/lib/unixtime"
"github.com/gofiber/fiber/v2"
"github.com/go-oidfed/lib"
)
// AddHistoricalKeysEndpoint adds the federation historical keys endpoint
func (fed *LightHouse) AddHistoricalKeysEndpoint(
endpoint EndpointConf, historyFnc func() jwx.JWKS,
) {
if endpoint.Path == "" {
return
}
signer := fed.GeneralJWTSigner.Typed(oidfedconst.JWTTypeJWKS)
fed.server.Get(
endpoint.Path, func(ctx *fiber.Ctx) error {
jwt, err := signer.JWT(
map[string]any{
"iss": fed.FederationEntity.EntityID,
"iat": unixtime.Now(),
"keys": historyFnc(),
},
)
if err != nil {
ctx.Status(fiber.StatusInternalServerError)
return ctx.JSON(oidfed.ErrorServerError(err.Error()))
}
ctx.Set(fiber.HeaderContentType, oidfedconst.ContentTypeJWKS)
return ctx.Send(jwt)
},
)
}