Changing JWT to use certificates

This commit is contained in:
2026-04-02 17:02:13 -04:00
parent a7109505a2
commit 12fc1bc76d
3 changed files with 11 additions and 24 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"context"
"crypto/rsa"
"encoding/json"
"fmt"
"libshared"
@@ -21,6 +22,8 @@ type AuthenticateResponse struct {
Token string `json:"token"`
}
var privateKey *rsa.PrivateKey
func authenticateHandler(w http.ResponseWriter, r *http.Request) {
var authenticaterequest AuthenticateRequest
@@ -29,7 +32,7 @@ func authenticateHandler(w http.ResponseWriter, r *http.Request) {
var hashText string
var ok bool
var token string
secret := []byte("super-secret-key")
//secret := []byte("super-secret-key")
w.Header().Set("Content-Type", "application/json")
// Only allow POST method
@@ -102,7 +105,7 @@ func authenticateHandler(w http.ResponseWriter, r *http.Request) {
return
}
token, err = createJWT(secret, fmt.Sprintf("%d", authenticaterequest.Accountid), authenticaterequest.Username, "user")
token, err = libshared.CreateJWT(privateKey, fmt.Sprintf("%d", authenticaterequest.Accountid), authenticaterequest.Username, "user")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
apiresponse := libshared.NewAPIResponse("fail", "Failed to create JWT", AuthenticateResponse{})