Skip to content

Commit 67ba7a1

Browse files
Merge pull request #2265 from ariary/master
Add parametrization of grant type supported in discovery endpoint
2 parents ff6e7c7 + 7bc9662 commit 67ba7a1

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

server/handlers.go

100644100755
+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ func (s *Server) discoveryHandler() (http.HandlerFunc, error) {
9494
UserInfo: s.absURL("/userinfo"),
9595
DeviceEndpoint: s.absURL("/device/code"),
9696
Subjects: []string{"public"},
97-
GrantTypes: []string{grantTypeAuthorizationCode, grantTypeRefreshToken, grantTypeDeviceCode},
9897
IDTokenAlgs: []string{string(jose.RS256)},
9998
CodeChallengeAlgs: []string{codeChallengeMethodS256, codeChallengeMethodPlain},
10099
Scopes: []string{"openid", "email", "groups", "profile", "offline_access"},
@@ -110,6 +109,8 @@ func (s *Server) discoveryHandler() (http.HandlerFunc, error) {
110109
}
111110
sort.Strings(d.ResponseTypes)
112111

112+
d.GrantTypes = s.supportedGrantTypes
113+
113114
data, err := json.MarshalIndent(d, "", " ")
114115
if err != nil {
115116
return nil, fmt.Errorf("failed to marshal discovery data: %v", err)

server/server.go

100644100755
+13-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/url"
1212
"os"
1313
"path"
14+
"sort"
1415
"strconv"
1516
"strings"
1617
"sync"
@@ -169,6 +170,8 @@ type Server struct {
169170

170171
supportedResponseTypes map[string]bool
171172

173+
supportedGrantTypes []string
174+
172175
now func() time.Time
173176

174177
idTokensValidFor time.Duration
@@ -209,15 +212,21 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
209212
c.SupportedResponseTypes = []string{responseTypeCode}
210213
}
211214

212-
supported := make(map[string]bool)
215+
supportedRes := make(map[string]bool)
213216
for _, respType := range c.SupportedResponseTypes {
214217
switch respType {
215218
case responseTypeCode, responseTypeIDToken, responseTypeToken:
216219
default:
217220
return nil, fmt.Errorf("unsupported response_type %q", respType)
218221
}
219-
supported[respType] = true
222+
supportedRes[respType] = true
223+
}
224+
225+
supportedGrant := []string{grantTypeAuthorizationCode, grantTypeRefreshToken, grantTypeDeviceCode} // default
226+
if c.PasswordConnector != "" {
227+
supportedGrant = append(supportedGrant, grantTypePassword)
220228
}
229+
sort.Strings(supportedGrant)
221230

222231
webFS := web.FS()
223232
if c.Web.Dir != "" {
@@ -249,7 +258,8 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
249258
issuerURL: *issuerURL,
250259
connectors: make(map[string]Connector),
251260
storage: newKeyCacher(c.Storage, now),
252-
supportedResponseTypes: supported,
261+
supportedResponseTypes: supportedRes,
262+
supportedGrantTypes: supportedGrant,
253263
idTokensValidFor: value(c.IDTokensValidFor, 24*time.Hour),
254264
authRequestsValidFor: value(c.AuthRequestsValidFor, 24*time.Hour),
255265
deviceRequestsValidFor: value(c.DeviceRequestsValidFor, 5*time.Minute),

0 commit comments

Comments
 (0)