Move to git.themmonk.com
This commit is contained in:
46
internal/httpserver/api/authenticate.go
Normal file
46
internal/httpserver/api/authenticate.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func RegisterAuthEndpoints() {
|
||||
fmt.Println("TODO: change access token format from uuid to a more secure format")
|
||||
|
||||
http.HandleFunc("/auth/user_and_pass", EndpointAuthUserAndPass)
|
||||
http.HandleFunc("/auth/check_access_token", EndpointAuthCheckAccessToken)
|
||||
}
|
||||
|
||||
type returnEndpointAuthUserAndPass struct {
|
||||
AccessToken string
|
||||
}
|
||||
|
||||
func EndpointAuthUserAndPass(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("STUB WARNING: EndpointAuthUserAndPass, need to check method and implement authentication")
|
||||
|
||||
//gopls doesnt like this line unless prefixed with var, may be a skill issue on my end
|
||||
var ret returnEndpointAuthUserAndPass
|
||||
ret.AccessToken = uuid.New().String()
|
||||
|
||||
retJson, err := json.Marshal(ret)
|
||||
if err != nil {
|
||||
fmt.Println("API warning: failed to marshal /auth/user_and_pass response")
|
||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
//w.WriteHeader(http.StatusUnauthorized)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write(retJson)
|
||||
}
|
||||
|
||||
func EndpointAuthCheckAccessToken(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("STUB WARNING: EndpointAuthCheckToken, need to check method and implement authentication")
|
||||
|
||||
//w.WriteHeader(http.StatusUnauthorized)
|
||||
}
|
||||
Reference in New Issue
Block a user