Skip to content

Commit 379c5b8

Browse files
add payload to auth request
1 parent 0c1f8ad commit 379c5b8

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

internal/api/client.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/localstack/lstk/internal/env"
13+
"github.com/localstack/lstk/internal/version"
1314
)
1415

1516
type PlatformAPI interface {
@@ -73,10 +74,20 @@ func NewPlatformClient() *PlatformClient {
7374
}
7475

7576
func (c *PlatformClient) CreateAuthRequest(ctx context.Context) (*AuthRequest, error) {
76-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/v1/auth/request", nil)
77+
payload := map[string]string{
78+
"actor": "cli-v2",
79+
"version": version.Version(),
80+
}
81+
body, err := json.Marshal(payload)
82+
if err != nil {
83+
return nil, fmt.Errorf("failed to marshal request: %w", err)
84+
}
85+
86+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/v1/auth/request", bytes.NewReader(body))
7787
if err != nil {
7888
return nil, fmt.Errorf("failed to create request: %w", err)
7989
}
90+
req.Header.Set("Content-Type", "application/json")
8091

8192
resp, err := c.httpClient.Do(req)
8293
if err != nil {

test/integration/login_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ func createMockAPIServer(t *testing.T, licenseToken string, confirmed bool) *htt
2828
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2929
switch {
3030
case r.Method == "POST" && r.URL.Path == "/v1/auth/request":
31+
// Validate request payload
32+
var payload map[string]string
33+
err := json.NewDecoder(r.Body).Decode(&payload)
34+
require.NoError(t, err, "failed to decode auth request payload")
35+
assert.Equal(t, "cli-v2", payload["actor"], "actor should be cli-v2")
36+
assert.NotEmpty(t, payload["version"], "version should not be empty")
37+
3138
w.WriteHeader(http.StatusCreated)
32-
err := json.NewEncoder(w).Encode(map[string]string{
39+
err = json.NewEncoder(w).Encode(map[string]string{
3340
"id": authReqID,
3441
"code": "TEST123",
3542
"exchange_token": exchangeToken,

0 commit comments

Comments
 (0)