Browse Source

fix: device code should not require scope

As per RFC8628 section 3.1, https://datatracker.ietf.org/doc/html/rfc8628#section-3.1
the scope is optional. Since dex always requires at least 'openid',
default the value to comply with the RFC.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
pull/4203/head
Doug Goldstein 9 months ago
parent
commit
d6237a8a6e
No known key found for this signature in database
  1. 6
      server/deviceflowhandlers.go
  2. 8
      server/deviceflowhandlers_test.go

6
server/deviceflowhandlers.go

@ -85,6 +85,12 @@ func (s *Server) handleDeviceCode(w http.ResponseWriter, r *http.Request) {
return
}
if len(scopes) == 0 {
// per RFC8628 section 3.1, https://datatracker.ietf.org/doc/html/rfc8628#section-3.1
// scope is optional but dex requires that it is always at least 'openid' so default it
scopes = []string{"openid"}
}
s.logger.InfoContext(r.Context(), "received device request", "client_id", clientID, "scoped", scopes)
// Make device code

8
server/deviceflowhandlers_test.go

@ -90,6 +90,14 @@ func TestHandleDeviceCode(t *testing.T) {
expectedResponseCode: http.StatusBadRequest,
expectedContentType: "application/json",
},
{
testName: "New Code without scope",
clientID: "test",
requestType: "POST",
scopes: []string{},
expectedResponseCode: http.StatusOK,
expectedContentType: "application/json",
},
}
for _, tc := range tests {
t.Run(tc.testName, func(t *testing.T) {

Loading…
Cancel
Save