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())
|
||||
|
||||
Reference in New Issue
Block a user