Scoped oauth
This commit is contained in:
@@ -7,18 +7,21 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"local/oauth2/oauth2server/config"
|
||||
"local/router"
|
||||
"net/http"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (s *Server) usersLog(w http.ResponseWriter, r *http.Request) {
|
||||
scope := ""
|
||||
router.Params(r, &scope)
|
||||
s.limiter.Wait(r.Context())
|
||||
q := r.URL.Query()
|
||||
fmt.Fprintln(w, `
|
||||
<html>
|
||||
<body>
|
||||
<form method="post" action="/authorize?`+q.Encode()+`">
|
||||
<form method="post" action="/authorize/`+scope+`?`+q.Encode()+`">
|
||||
<input type="password" name="username"></input>
|
||||
<input type="submit"></input>
|
||||
</form>
|
||||
@@ -28,11 +31,13 @@ func (s *Server) usersLog(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) usersRegister(w http.ResponseWriter, r *http.Request) {
|
||||
scope := ""
|
||||
router.Params(r, &scope)
|
||||
s.limiter.Wait(r.Context())
|
||||
fmt.Fprintln(w, `
|
||||
<html>
|
||||
<body>
|
||||
<form method="post" action="/users/submit">
|
||||
<form method="post" action="/users/submit/`+scope+`">
|
||||
<input type="text" name="username"></input>
|
||||
<input type="submit"></input>
|
||||
</form>
|
||||
@@ -42,12 +47,14 @@ func (s *Server) usersRegister(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Server) usersSubmit(w http.ResponseWriter, r *http.Request) {
|
||||
scope := ""
|
||||
router.Params(r, &scope)
|
||||
s.limiter.Wait(r.Context())
|
||||
if r.Method != "POST" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
id := r.FormValue("username")
|
||||
id := scope + "." + r.FormValue("username")
|
||||
if _, ok := s.getUser(id); ok {
|
||||
http.Error(w, "user already exists", http.StatusConflict)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user