Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use /token endpoint to get tokens with device flow #2010

Merged

Conversation

nabokihms
Copy link
Member

@nabokihms nabokihms commented Feb 20, 2021

Signed-off-by: m.nabokikh maksim.nabokikh@flant.com

Overview

rfc6749#section-3.2

  • Make /token endpoint responding to requests with device auth grant
  • Allow only POST requests /token endpoint
  • Do not search for a client in storage if an invalid grant type is provided

What this PR does / why we need it

Fixes #1953
As was mentioned in the issue above, the main problem that the token endpoint is not discoverable.

Special notes for your reviewer

This MR leaves the possibility to get a token from the /device/token endpoint.

Does this PR introduce a user-facing change?

There are no breaking changes, but it will be better to avoid using /device/token endpoint in the feature.

Make `/token` endpoint responding to requests with device auth grant. The `/device/token` endpoint becomes DEPRECATED.

@sagikazarmark
Copy link
Member

Should we deprecate the /device/token endpoint?

@sagikazarmark sagikazarmark added this to the v2.29.0 milestone Feb 20, 2021
@nabokihms
Copy link
Member Author

Yes, I think so. I left a to-do but did nothing with deprecation. Maybe adding some sort of warning on endpoint call will be good enough.
"Some of Dex clients called the deprecated /device/token endpoint. It will be removed in a future release."

Something like this.

@sagikazarmark
Copy link
Member

For me, deprecation would mean

  • a comment in the code somewhere
  • potentially a warning log message
  • a note in the release notes

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
@nabokihms nabokihms force-pushed the switch-device-token-endpoint-to-token branch from ab8b38b to 9ed5cc0 Compare February 24, 2021 13:24
Comment on lines 155 to 156
s.logger.Warn(`Request to the deprecated "/device/token" endpoint was received.`)
s.logger.Warn(`The "/device/token" endpoint will be removed in a future release.`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a single log line? And maybe make the message a bit more concise?

@@ -1583,7 +1583,7 @@ func TestOAuth2DeviceFlow(t *testing.T) {

// Hit the Token Endpoint, and try and get an access token
tokenURL, _ := url.Parse(issuer.String())
tokenURL.Path = path.Join(tokenURL.Path, "/device/token")
tokenURL.Path = path.Join(tokenURL.Path, "/token")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test with the old path to make sure it's still functional?

@@ -151,7 +151,10 @@ func (s *Server) handleDeviceCode(w http.ResponseWriter, r *http.Request) {
}
}

func (s *Server) handleDeviceToken(w http.ResponseWriter, r *http.Request) {
func (s *Server) handleDeviceTokenGrant(w http.ResponseWriter, r *http.Request) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this name is a bit confusing and ambiguous with the handleDeviceToken name. Maybe call it something like deprecatedDeviceTokenHandler or handleDeviceTokenDeprecated.

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
Copy link
Member

@sagikazarmark sagikazarmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@justenwalker
Copy link

@sagikazarmark Anything preventing this from being merged/closed?

@sagikazarmark sagikazarmark merged commit 94a2b3e into dexidp:master May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

device auth flow token endpoint is not discoverable
3 participants