Updating JWT to use certificates
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user