fix: need to override claim validation to convert string exp to unix

This commit is contained in:
Derrick Hammer 2024-02-12 02:19:09 -05:00
parent 276b43ddd0
commit f975cf38e0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 18 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"time"
) )
const AUTHED_CONTEXT_KEY = "authed" const AUTHED_CONTEXT_KEY = "authed"
@ -25,11 +26,27 @@ const WEBHOOK_CONTEXT_KEY = "webhook"
const AuthCookieName = "auth-token" const AuthCookieName = "auth-token"
var _ = jwt.Claims(&standardClaims{})
type standardClaims struct { type standardClaims struct {
Issuer any `json:"iss,omitempty"` Issuer any `json:"iss,omitempty"`
ExpiresAt any `json:"exp,omitempty"`
jwt.StandardClaims jwt.StandardClaims
} }
func (s *standardClaims) Valid() error {
if timeStr, ok := s.ExpiresAt.(string); ok {
t, err := time.Parse(time.RFC3339Nano, timeStr)
if err != nil {
return err
}
unixTimestamp := t.Unix()
s.ExpiresAt = unixTimestamp
}
return s.StandardClaims.Valid()
}
func findAuthToken(r *http.Request) string { func findAuthToken(r *http.Request) string {
authHeader := parseAuthTokenHeader(r.Header) authHeader := parseAuthTokenHeader(r.Header)