Updating JWT to use certificates

This commit is contained in:
2026-04-02 17:04:13 -04:00
parent 571aab64bb
commit 22a23c0062
6 changed files with 20 additions and 67 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"context"
"crypto/rsa"
"encoding/json"
"fmt"
"io"
@@ -26,6 +27,8 @@ type AssumeRoleResponse struct {
Token string `json:"token"`
}
var privateKey *rsa.PrivateKey
func assumeRole(w http.ResponseWriter, r *http.Request) {
log.Println("Assume Role Request")
@@ -131,7 +134,7 @@ func assumeRole(w http.ResponseWriter, r *http.Request) {
// Prevent duplication of roles with the same name for the same account
checkExisting := pool.QueryRow(context.Background(),
checkExisting := libshared.Pool.QueryRow(context.Background(),
"SELECT id FROM roles WHERE accountid = $1 AND rolename = $2",
claims.Account, role.Rolename)
@@ -146,7 +149,7 @@ func assumeRole(w http.ResponseWriter, r *http.Request) {
fmt.Println("Role ID", existingRoleID)
roleToken, err := createJWT(secret, claims.Account, role.Rolename)
roleToken, err := libshared.CreateJWT(privateKey, claims.Account, role.Rolename, "role")
if err != nil {
log.Println("Error creating JWT:", err)
w.WriteHeader(http.StatusInternalServerError)