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

@@ -45,6 +45,7 @@ func TestAll(t *testing.T) {
func launchServer() (*httptest.Server, error) {
config.Store = "map"
config.UserRegistration = true
oauth2server := server.New()
err := oauth2server.Routes()
@@ -62,7 +63,7 @@ func launchServer() (*httptest.Server, error) {
func dummyServer(oauth2server string) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
err := oauth2client.Authenticate(oauth2server, w, r)
err := oauth2client.Authenticate(oauth2server, "scope", w, r)
if err != nil {
return
}
@@ -71,7 +72,7 @@ func dummyServer(oauth2server string) *httptest.Server {
}
func createUser(oauth2server string) error {
resp, err := http.Post(oauth2server+"/users/submit", "application/x-www-form-urlencoded", strings.NewReader("username=abc"))
resp, err := http.Post(oauth2server+"/users/submit/scope", "application/x-www-form-urlencoded", strings.NewReader("username=abc"))
if err != nil {
return err
}
@@ -83,7 +84,7 @@ func createUser(oauth2server string) error {
}
func logUser(oauth2server string) error {
resp, err := http.Post(oauth2server+"/authorize", "application/x-www-form-urlencoded", strings.NewReader("username=abc"))
resp, err := http.Post(oauth2server+"/authorize/scope", "application/x-www-form-urlencoded", strings.NewReader("username=abc"))
if err != nil {
return err
}
@@ -106,7 +107,7 @@ func clientShouldRedir(c *http.Client, dummy string) error {
return err
}
defer resp.Body.Close()
if resp.Request.URL.Path != "/users/log" {
if resp.Request.URL.Path != "/users/log/scope" {
return fmt.Errorf("did not need redir without auth: %v", resp.Request.URL)
}
return nil
@@ -119,7 +120,7 @@ func clientShouldNotRedir(c *http.Client, dummy string) error {
return err
}
defer resp.Body.Close()
if resp.Request.URL.Path == "/users/log" {
if resp.Request.URL.Path == "/users/log/scope" {
return fmt.Errorf("did redir with auth: %v", resp.Request.URL.Path)
}
return nil
@@ -147,7 +148,7 @@ func testAuth(oauth2server, dummy string) error {
}
func clientLogin(c *http.Client, oauth2server string) (string, error) {
req, _ := http.NewRequest("POST", oauth2server+"/authorize?"+oauth2.REDIRECT+"="+oauth2server+"/", strings.NewReader("username=abc"))
req, _ := http.NewRequest("POST", oauth2server+"/authorize/scope?"+oauth2.REDIRECT+"="+oauth2server+"/", strings.NewReader("username=abc"))
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, err := c.Do(req)
if err != nil {