Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
0dcf1bcf
Commit
0dcf1bcf
authored
Jan 27, 2017
by
Eric Chiang
Committed by
GitHub
Jan 27, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #792 from ericchiang/auth-endpoint-post
server: support POSTing to authorization endpoint
parents
36883d0b
8541184a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
oauth2.go
server/oauth2.go
+4
-1
oauth2_test.go
server/oauth2_test.go
+29
-1
No files found.
server/oauth2.go
View file @
0dcf1bcf
...
...
@@ -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."
}
...
...
server/oauth2_test.go
View file @
0dcf1bcf
...
...
@@ -2,8 +2,10 @@ package server
import
(
"context"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
jose
"gopkg.in/square/go-jose.v2"
...
...
@@ -17,6 +19,8 @@ func TestParseAuthorizationRequest(t *testing.T) {
clients
[]
storage
.
Client
supportedResponseTypes
[]
string
usePOST
bool
queryParams
map
[
string
]
string
wantErr
bool
...
...
@@ -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
{
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment