Rate limit login stuff
parent
cc41444b21
commit
80017bb32b
|
|
@ -11,6 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) authorize(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) authorize(w http.ResponseWriter, r *http.Request) {
|
||||||
|
s.limiter.Wait(r.Context())
|
||||||
if r.Method != "POST" {
|
if r.Method != "POST" {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"local/oauth2/oauth2server/config"
|
"local/oauth2/oauth2server/config"
|
||||||
"local/router"
|
"local/router"
|
||||||
"local/storage"
|
"local/storage"
|
||||||
|
|
||||||
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
var wildcard = router.Wildcard
|
var wildcard = router.Wildcard
|
||||||
|
|
@ -17,7 +19,8 @@ const (
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
*router.Router
|
*router.Router
|
||||||
store storage.DB
|
store storage.DB
|
||||||
|
limiter *rate.Limiter
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Server {
|
func New() *Server {
|
||||||
|
|
@ -27,8 +30,9 @@ func New() *Server {
|
||||||
}
|
}
|
||||||
purgeIssuedCredentials(store)
|
purgeIssuedCredentials(store)
|
||||||
return &Server{
|
return &Server{
|
||||||
Router: router.New(),
|
Router: router.New(),
|
||||||
store: store,
|
store: store,
|
||||||
|
limiter: rate.NewLimiter(1, 3),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) usersLog(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) usersLog(w http.ResponseWriter, r *http.Request) {
|
||||||
|
s.limiter.Wait(r.Context())
|
||||||
q := r.URL.Query()
|
q := r.URL.Query()
|
||||||
fmt.Fprintln(w, `
|
fmt.Fprintln(w, `
|
||||||
<html>
|
<html>
|
||||||
|
|
@ -27,6 +28,7 @@ func (s *Server) usersLog(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) usersRegister(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) usersRegister(w http.ResponseWriter, r *http.Request) {
|
||||||
|
s.limiter.Wait(r.Context())
|
||||||
fmt.Fprintln(w, `
|
fmt.Fprintln(w, `
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
|
|
@ -40,6 +42,7 @@ func (s *Server) usersRegister(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) usersSubmit(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) usersSubmit(w http.ResponseWriter, r *http.Request) {
|
||||||
|
s.limiter.Wait(r.Context())
|
||||||
if r.Method != "POST" {
|
if r.Method != "POST" {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue