Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: support POSTing to authorization endpoint #792

Merged
merged 1 commit into from Jan 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion server/oauth2.go
Expand Up @@ -333,7 +333,10 @@ func (s *Server) newIDToken(clientID string, claims storage.Claims, scopes []str

// parse the initial request from the OAuth2 client.
func (s *Server) parseAuthorizationRequest(r *http.Request) (req storage.AuthRequest, oauth2Err *authErr) {
q := r.URL.Query()
if err := r.ParseForm(); err != nil {
return req, &authErr{"", "", errInvalidRequest, "Failed to parse request body."}
}
q := r.Form
redirectURI, err := url.QueryUnescape(q.Get("redirect_uri"))
if err != nil {
return req, &authErr{"", "", errInvalidRequest, "No redirect_uri provided."}
Expand Down
30 changes: 29 additions & 1 deletion server/oauth2_test.go
Expand Up @@ -2,8 +2,10 @@ package server

import (
"context"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"

jose "gopkg.in/square/go-jose.v2"
Expand All @@ -17,6 +19,8 @@ func TestParseAuthorizationRequest(t *testing.T) {
clients []storage.Client
supportedResponseTypes []string

usePOST bool

queryParams map[string]string

wantErr bool
Expand All @@ -37,6 +41,23 @@ func TestParseAuthorizationRequest(t *testing.T) {
"scope": "openid email profile",
},
},
{
name: "POST request",
clients: []storage.Client{
{
ID: "foo",
RedirectURIs: []string{"https://example.com/foo"},
},
},
supportedResponseTypes: []string{"code"},
queryParams: map[string]string{
"client_id": "foo",
"redirect_uri": "https://example.com/foo",
"response_type": "code",
"scope": "openid email profile",
},
usePOST: true,
},
{
name: "invalid client id",
clients: []storage.Client{
Expand Down Expand Up @@ -139,7 +160,14 @@ func TestParseAuthorizationRequest(t *testing.T) {
params.Set(k, v)
}

req := httptest.NewRequest("GET", httpServer.URL+"/auth?"+params.Encode(), nil)
var req *http.Request
if tc.usePOST {
body := strings.NewReader(params.Encode())
req = httptest.NewRequest("POST", httpServer.URL+"/auth", body)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
} else {
req = httptest.NewRequest("GET", httpServer.URL+"/auth?"+params.Encode(), nil)
}
_, err := server.parseAuthorizationRequest(req)
if err != nil && !tc.wantErr {
t.Errorf("%s: %v", tc.name, err)
Expand Down