Scoped oauth

This commit is contained in:
Bel LaPointe
2019-11-02 08:03:54 -06:00
parent ba44094eb9
commit 08add4b521
7 changed files with 48 additions and 31 deletions

View File

@@ -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