func CreateToken() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPost:
u := auth.User(r)
//What should I do here? how can I add the jwt to the RotatedSecrets
// And how can I add extra fields to the token for example permissions, so the token will include permissions: "kill","example"
token, err := jwt.IssueAccessToken(u, ??)
if err != nil {
//something
}
body := fmt.Sprintf("token: %s \n", token)
w.Write([]byte(body))
default:
http.Error(w, "method is not allowed", http.StatusMethodNotAllowed)
return
}
}
}
And what should I do with the rotatedSecret struct
type RotatedSecrets struct {
Secrets map[string][]byte
LatestID string
RotationDuration time.Duration
LastRotation time.Time
}
func (r RotatedSecrets) KID() string {
if time.Now().After(r.LastRotation) {
r.LastRotation = time.Now().Add(r.RotationDuration)
r.LatestID = "your generated id"
r.Secrets[r.LatestID] = []byte("your generated secrets") <<<<<where should I get the generated secrets?
}
return r.LatestID
}
func (r RotatedSecrets) Get(kid string) (key interface{}, alg string, err error) {
s, ok := r.Secrets[kid]
if ok {
return s, jwt.HS256, nil
}
return nil, "", fmt.Errorf("Invalid KID %s", kid)
}
Main
SetupGoGuardian
Auth Middleware
Controller CreateToken
And what should I do with the rotatedSecret struct