Certificates Renewal + SSE

- Certificate renewal is just a re-request as it's forced already
- Rejig the routes for readability
- Added Server Side Events so that the UI would invalidate the
cache when changes happen on the backend, such as certs being
provided or failing
- Added a SSE Token, which has the same shelf life as normal token
but can't be used interchangeably. The reason for this is, the
SSE endpoint needs a token for auth as a Query param, so it would
be stored in log files. If someone where to get a hold of that,
it's pretty useless as it can't be used to change anything, only
to listen for events until it expires
- Added test endpoint for SSE testing only availabe in debug mode
This commit is contained in:
Jamie Curnow
2023-03-07 16:42:26 +10:00
parent 35550082bf
commit 215083f6cf
29 changed files with 665 additions and 197 deletions

View File

@ -24,11 +24,16 @@ type GeneratedResponse struct {
}
// Generate will create a JWT
func Generate(userObj *user.Model) (GeneratedResponse, error) {
func Generate(userObj *user.Model, forSSE bool) (GeneratedResponse, error) {
var response GeneratedResponse
key, _ := GetPrivateKey()
expires := time.Now().AddDate(0, 0, 1) // 1 day
issuer := "api"
if forSSE {
issuer = "sse"
}
// Create the Claims
claims := UserJWTClaims{
@ -37,7 +42,7 @@ func Generate(userObj *user.Model) (GeneratedResponse, error) {
jwt.StandardClaims{
IssuedAt: time.Now().Unix(),
ExpiresAt: expires.Unix(),
Issuer: "api",
Issuer: issuer,
},
}