diff --git a/pkg/client/devicegrant/devicegrant.go b/pkg/client/devicegrant/devicegrant.go index 625b2aa..bbd200b 100644 --- a/pkg/client/devicegrant/devicegrant.go +++ b/pkg/client/devicegrant/devicegrant.go @@ -19,24 +19,28 @@ const authorizationPendingAPIMsg = "authorization_pending" var ErrAuthorizationPending = errors.New("authorization pending") type DeviceGrant struct { - DeviceCode string `json:"deviceCode"` - UserCode string `json:"userCode"` - VerificationUri string `json:"verificationUri"` - ExpiresIn int `json:"expiresIn"` - Interval int `json:"interval"` + DeviceCode string `json:"device_code"` + UserCode string `json:"user_code"` + VerificationUri string `json:"verification_uri"` + VerificationUriComplete string `json:"verification_uri_complete"` + ExpiresIn int `json:"expires_in"` + Interval int `json:"interval"` } type GrantRequestBody struct { - ClientID string `json:"clientId"` + ClientID string `json:"client_id"` } type DeviceToken struct { - DeviceToken string `json:"deviceToken"` + AccessToken string `json:"access_token"` + TokenType string `json:"token_type"` + ExpiresIn int `json:"expires_in"` } type TokenRequestBody struct { - ClientID string `json:"clientId"` - DeviceCode string `json:"deviceCode"` + GrantType string `json:"grant_type"` + ClientID string `json:"client_id"` + DeviceCode string `json:"device_code"` } type ErrorResponse struct { @@ -73,7 +77,10 @@ func (c *Client) CreateGrant(ctx context.Context) (*DeviceGrant, error) { } func (c *Client) GetDeviceToken(ctx context.Context, dg *DeviceGrant) (string, error) { - body := &TokenRequestBody{ClientID: cliOauthClientID, DeviceCode: dg.DeviceCode} + body := &TokenRequestBody{ + ClientID: cliOauthClientID, DeviceCode: dg.DeviceCode, + GrantType: "urn:ietf:params:oauth:grant-type:device_code", + } var token DeviceToken err := c.postFor(ctx, "/device-token", body, &token) @@ -85,7 +92,7 @@ func (c *Client) GetDeviceToken(ctx context.Context, dg *DeviceGrant) (string, e return "", err } - return token.DeviceToken, nil + return token.AccessToken, nil } func (c *Client) postFor(ctx context.Context, path string, body any, v any) error { @@ -101,6 +108,7 @@ func (c *Client) postFor(ctx context.Context, path string, body any, v any) erro } req = req.WithContext(ctx) + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") resp, err := c.Do(req) if err != nil { return err diff --git a/pkg/client/devicegrant/devicegrant_test.go b/pkg/client/devicegrant/devicegrant_test.go index fa4ab23..2a36fe0 100644 --- a/pkg/client/devicegrant/devicegrant_test.go +++ b/pkg/client/devicegrant/devicegrant_test.go @@ -28,11 +28,12 @@ func TestClient_CreateGrant(t *testing.T) { require.NoError(t, err) assert.Equal(t, &devicegrant.DeviceGrant{ - DeviceCode: "some device code", - UserCode: "some user code", - VerificationUri: "some verification uri", - ExpiresIn: 1, - Interval: 2, + DeviceCode: "some device code", + UserCode: "some user code", + VerificationUri: "some verification uri", + VerificationUriComplete: "some complete verification uri", + ExpiresIn: 1, + Interval: 2, }, dg) } @@ -79,11 +80,12 @@ func TestClient_GetDeviceToken(t *testing.T) { } const deviceGrantResp = `{ - "deviceCode": "some device code", - "userCode": "some user code", - "verificationUri": "some verification uri", - "expiresIn": 1, + "device_code": "some device code", + "user_code": "some user code", + "verification_uri": "some verification uri", + "verification_uri_complete": "some complete verification uri", + "expires_in": 1, "interval": 2 }` -const deviceTokenResp = `{"deviceToken": "some device token"}` +const deviceTokenResp = `{"access_token": "some device token"}` diff --git a/pkg/tui/views/login.go b/pkg/tui/views/login.go index c0d71ca..7e98fb0 100644 --- a/pkg/tui/views/login.go +++ b/pkg/tui/views/login.go @@ -197,7 +197,7 @@ func isAlreadyLoggedIn(ctx context.Context) bool { } func dashboardAuthURL(dg *devicegrant.DeviceGrant) (*url.URL, error) { - u, err := url.Parse(dg.VerificationUri) + u, err := url.Parse(dg.VerificationUriComplete) if err != nil { return nil, err }