Skip to content

Commit

Permalink
Allow public clients (e.g. with PKCE) to have redirect URIs configured
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Heide <[email protected]>
  • Loading branch information
heidemn-faro committed Oct 5, 2020
1 parent 1059ba7 commit b6e297b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
13 changes: 8 additions & 5 deletions server/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,15 @@ func (s *Server) validateCrossClientTrust(clientID, peerID string) (trusted bool
}

func validateRedirectURI(client storage.Client, redirectURI string) bool {
if !client.Public {
for _, uri := range client.RedirectURIs {
if redirectURI == uri {
return true
}
// Allow named RedirectURIs for both public and non-public clients.
// This is required make PKCE-enabled web apps work, when configured as public clients.
for _, uri := range client.RedirectURIs {
if redirectURI == uri {
return true
}
}
// For non-public clients, only named RedirectURIs are allowed.
if !client.Public {
return false
}

Expand Down
25 changes: 25 additions & 0 deletions server/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ func TestValidRedirectURI(t *testing.T) {
RedirectURIs: []string{"http://foo.com/bar"},
},
redirectURI: "http://foo.com/bar/baz",
wantValid: false,
},
{
client: storage.Client{
Expand Down Expand Up @@ -369,6 +370,30 @@ func TestValidRedirectURI(t *testing.T) {
redirectURI: "http://localhost",
wantValid: true,
},
// Both Public + RedirectURIs configured: Could e.g. be a PKCE-enabled web app.
{
client: storage.Client{
Public: true,
RedirectURIs: []string{"http://foo.com/bar"},
},
redirectURI: "http://foo.com/bar",
wantValid: true,
},
{
client: storage.Client{
Public: true,
RedirectURIs: []string{"http://foo.com/bar"},
},
redirectURI: "http://foo.com/bar/baz",
wantValid: false,
},
{
client: storage.Client{
Public: true,
},
redirectURI: "http://foo.com/bar",
wantValid: false,
},
{
client: storage.Client{
Public: true,
Expand Down

0 comments on commit b6e297b

Please sign in to comment.