40 lines
961 B
Go
40 lines
961 B
Go
package security
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
var sysKey = "devtoken"
|
|
var dscSecret = "dscSec"
|
|
var webSecret = "webSec"
|
|
|
|
func SecurityRouter(r chi.Router) {
|
|
r.Get("/", login)
|
|
}
|
|
|
|
/* ==============================================================
|
|
TODO rework to make use of JWT
|
|
============================================================== */
|
|
|
|
// [DEPRECATED] will be replaced with jwt
|
|
// login takes in requered parameters from all incoming platforms and authorizes access if granted
|
|
func login(w http.ResponseWriter, r *http.Request) {
|
|
loginInput := r.URL.Query()
|
|
|
|
switch loginInput.Get("platform") {
|
|
case "discord":
|
|
if loginInput.Get("s") == dscSecret {
|
|
w.Write([]byte(`{"type":"reply", "s":"` + sysKey + `"}`))
|
|
}
|
|
case "web":
|
|
if loginInput.Get("s") == webSecret {
|
|
w.Write([]byte(`{"type":"reply", "s":"` + sysKey + `"}`))
|
|
}
|
|
default:
|
|
http.Error(w, "invalid_platform", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
}
|