databag/net/server/internal/api_authorize.go

41 lines
721 B
Go
Raw Normal View History

2022-01-11 06:20:32 +00:00
package databag
import (
"net/http"
2022-01-18 08:40:39 +00:00
"time"
2022-01-11 06:20:32 +00:00
)
2022-01-13 05:23:18 +00:00
func Authorize(w http.ResponseWriter, r *http.Request) {
account, res := BearerAppToken(r);
if res != nil {
w.WriteHeader(http.StatusUnauthorized)
return
}
if account.Disabled {
w.WriteHeader(http.StatusGone);
return
}
2022-01-18 08:40:39 +00:00
// extract token from body
var token string
if ParseRequest(r, w, &token) != nil {
w.WriteHeader(http.StatusBadRequest);
return
}
// load details to sign data
// generate message
auth := Authenticate{
Guid: account.Guid,
Token: token,
Timestamp: time.Now().Unix(),
}
PrintMsg(auth);
2022-01-11 06:20:32 +00:00
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}