Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
8541184a
Commit
8541184a
authored
8 years ago
by
Eric Chiang
Browse files
Options
Downloads
Patches
Plain Diff
server: support POSTing to authorization endpoint
Fixes #791
parent
a3ef8d26
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/oauth2.go
+4
-1
4 additions, 1 deletion
server/oauth2.go
server/oauth2_test.go
+29
-1
29 additions, 1 deletion
server/oauth2_test.go
with
33 additions
and
2 deletions
server/oauth2.go
+
4
−
1
View file @
8541184a
...
@@ -333,7 +333,10 @@ func (s *Server) newIDToken(clientID string, claims storage.Claims, scopes []str
...
@@ -333,7 +333,10 @@ func (s *Server) newIDToken(clientID string, claims storage.Claims, scopes []str
// parse the initial request from the OAuth2 client.
// parse the initial request from the OAuth2 client.
func
(
s
*
Server
)
parseAuthorizationRequest
(
r
*
http
.
Request
)
(
req
storage
.
AuthRequest
,
oauth2Err
*
authErr
)
{
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"
))
redirectURI
,
err
:=
url
.
QueryUnescape
(
q
.
Get
(
"redirect_uri"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
req
,
&
authErr
{
""
,
""
,
errInvalidRequest
,
"No redirect_uri provided."
}
return
req
,
&
authErr
{
""
,
""
,
errInvalidRequest
,
"No redirect_uri provided."
}
...
...
This diff is collapsed.
Click to expand it.
server/oauth2_test.go
+
29
−
1
View file @
8541184a
...
@@ -2,8 +2,10 @@ package server
...
@@ -2,8 +2,10 @@ package server
import
(
import
(
"context"
"context"
"net/http"
"net/http/httptest"
"net/http/httptest"
"net/url"
"net/url"
"strings"
"testing"
"testing"
jose
"gopkg.in/square/go-jose.v2"
jose
"gopkg.in/square/go-jose.v2"
...
@@ -17,6 +19,8 @@ func TestParseAuthorizationRequest(t *testing.T) {
...
@@ -17,6 +19,8 @@ func TestParseAuthorizationRequest(t *testing.T) {
clients
[]
storage
.
Client
clients
[]
storage
.
Client
supportedResponseTypes
[]
string
supportedResponseTypes
[]
string
usePOST
bool
queryParams
map
[
string
]
string
queryParams
map
[
string
]
string
wantErr
bool
wantErr
bool
...
@@ -37,6 +41,23 @@ func TestParseAuthorizationRequest(t *testing.T) {
...
@@ -37,6 +41,23 @@ func TestParseAuthorizationRequest(t *testing.T) {
"scope"
:
"openid email profile"
,
"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"
,
name
:
"invalid client id"
,
clients
:
[]
storage
.
Client
{
clients
:
[]
storage
.
Client
{
...
@@ -139,7 +160,14 @@ func TestParseAuthorizationRequest(t *testing.T) {
...
@@ -139,7 +160,14 @@ func TestParseAuthorizationRequest(t *testing.T) {
params
.
Set
(
k
,
v
)
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
)
_
,
err
:=
server
.
parseAuthorizationRequest
(
req
)
if
err
!=
nil
&&
!
tc
.
wantErr
{
if
err
!=
nil
&&
!
tc
.
wantErr
{
t
.
Errorf
(
"%s: %v"
,
tc
.
name
,
err
)
t
.
Errorf
(
"%s: %v"
,
tc
.
name
,
err
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment