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