Make /device/token deprecation warning more concise

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
This commit is contained in:
m.nabokikh 2021-02-25 11:53:25 +04:00
parent 9ed5cc00cf
commit 3bd0e91a68
3 changed files with 160 additions and 140 deletions

View file

@ -151,9 +151,8 @@ func (s *Server) handleDeviceCode(w http.ResponseWriter, r *http.Request) {
}
}
func (s *Server) handleDeviceTokenGrant(w http.ResponseWriter, r *http.Request) {
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.`)
func (s *Server) handleDeviceTokenDeprecated(w http.ResponseWriter, r *http.Request) {
s.logger.Warn(`The deprecated "/device/token" endpoint was called. It will be removed, use "/token" instead.`)
w.Header().Set("Content-Type", "application/json")
switch r.Method {

View file

@ -321,7 +321,7 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
handleFunc("/device/auth/verify_code", s.verifyUserCode)
handleFunc("/device/code", s.handleDeviceCode)
// TODO(nabokihms): "/device/token" endpoint is deprecated, consider using /token endpoint instead
handleFunc("/device/token", s.handleDeviceTokenGrant)
handleFunc("/device/token", s.handleDeviceTokenDeprecated)
handleFunc(deviceCallbackURI, s.handleDeviceCallback)
r.HandleFunc(path.Join(issuerURL.Path, "/callback"), func(w http.ResponseWriter, r *http.Request) {
// Strip the X-Remote-* headers to prevent security issues on

View file

@ -1497,8 +1497,28 @@ func TestOAuth2DeviceFlow(t *testing.T) {
var conn *mock.Callback
idTokensValidFor := time.Second * 30
for _, tc := range makeOAuth2Tests(clientID, clientSecret, now).tests {
func() {
tests := makeOAuth2Tests(clientID, clientSecret, now)
testCases := []struct {
name string
tokenEndpoint string
oauth2Tests oauth2Tests
}{
{
name: "Actual token endpoint for devices",
tokenEndpoint: "/token",
oauth2Tests: tests,
},
// TODO(nabokihms): delete temporary tests after removing the deprecated token endpoint support
{
name: "Deprecated token endpoint for devices",
tokenEndpoint: "/device/token",
oauth2Tests: tests,
},
}
for _, testCase := range testCases {
for _, tc := range testCase.oauth2Tests.tests {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@ -1583,7 +1603,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, "/token")
tokenURL.Path = path.Join(tokenURL.Path, testCase.tokenEndpoint)
v := url.Values{}
v.Add("grant_type", grantTypeDeviceCode)
v.Add("device_code", deviceCode.DeviceCode)
@ -1634,6 +1654,7 @@ func TestOAuth2DeviceFlow(t *testing.T) {
if err != nil {
t.Errorf("%s: %v", tc.name, err)
}
}()
})
}
}
}