Producing jwt tokens
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
/*
|
||||
* This API call authenticates a user
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -23,11 +19,21 @@ type AuthenticateRequest struct {
|
||||
|
||||
func authenticateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
/*
|
||||
var hashText string
|
||||
var salt []byte
|
||||
var err error
|
||||
var checkExisting pgx.Row
|
||||
var req CreateIdentityRequest
|
||||
var accountid string
|
||||
*/
|
||||
var authenticaterequest AuthenticateRequest
|
||||
var err error
|
||||
var checkExisting pgx.Row
|
||||
var hashText string
|
||||
var ok bool
|
||||
var token string
|
||||
secret := []byte("super-secret-key")
|
||||
|
||||
response := map[string]interface{}{}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -90,8 +96,17 @@ func authenticateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
goto ExitAPICall
|
||||
}
|
||||
|
||||
token, err = createJWT(secret, fmt.Sprintf("%d", authenticaterequest.Accountid), authenticaterequest.Username, "user")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
response["status"] = "error"
|
||||
response["message"] = "Failed to create JWT"
|
||||
goto ExitAPICall
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
response["status"] = "success"
|
||||
response["token"] = token
|
||||
ExitAPICall:
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
response["timestamp"] = fmt.Sprintf("%d", time.Now().Unix())
|
||||
|
||||
1
go.mod
1
go.mod
@@ -8,6 +8,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -1,6 +1,8 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
|
||||
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
|
||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
|
||||
Reference in New Issue
Block a user