Skip to content

Commit

Permalink
Uses query instead of fragment when handling unsupported response type
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas committed May 29, 2018
1 parent a958ab8 commit 48641b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion authorize_error.go
Expand Up @@ -25,6 +25,8 @@ import (
"encoding/json"
"net/http"
"net/url"

"github.com/pkg/errors"
)

func (c *Fosite) WriteAuthorizeError(rw http.ResponseWriter, ar AuthorizeRequester, err error) {
Expand Down Expand Up @@ -59,7 +61,7 @@ func (c *Fosite) WriteAuthorizeError(rw http.ResponseWriter, ar AuthorizeRequest
query.Add("error_hint", rfcerr.Hint)
}

if !ar.GetResponseTypes().Exact("code") {
if !ar.GetResponseTypes().Exact("code") && errors.Cause(err) != ErrUnsupportedResponseType {
redirectURI.Fragment = query.Encode()
} else {
for key, values := range redirectURI.Query() {
Expand Down
16 changes: 16 additions & 0 deletions authorize_error_test.go
Expand Up @@ -127,6 +127,22 @@ func TestWriteAuthorizeError(t *testing.T) {
assert.Equal(t, a, b)
},
},
{
err: ErrUnsupportedGrantType,
mock: func(rw *MockResponseWriter, req *MockAuthorizeRequester) {
req.EXPECT().IsRedirectURIValid().Return(true)
req.EXPECT().GetRedirectURI().Return(copyUrl(purls[1]))
req.EXPECT().GetState().Return("foostate")
req.EXPECT().GetResponseTypes().MaxTimes(2).Return(Arguments([]string{"foobar"}))
rw.EXPECT().Header().Return(header)
rw.EXPECT().WriteHeader(http.StatusFound)
},
checkHeader: func(t *testing.T, k int) {
a, _ := url.Parse("https://foobar.com/?foo=bar#error=unsupported_grant_type&error_description=The+authorization+grant+type+is+not+supported+by+the+authorization+server&state=foostate")
b, _ := url.Parse(header.Get("Location"))
assert.Equal(t, a, b)
},
},
{
err: ErrInvalidRequest,
mock: func(rw *MockResponseWriter, req *MockAuthorizeRequester) {
Expand Down

0 comments on commit 48641b2

Please sign in to comment.