Skip to content

Commit 3200ba4

Browse files
Add payload to auth request (#49)
1 parent 0c1f8ad commit 3200ba4

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

internal/api/client.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import (
1010
"time"
1111

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

16+
const actor = "lstk"
17+
1518
type PlatformAPI interface {
1619
CreateAuthRequest(ctx context.Context) (*AuthRequest, error)
1720
CheckAuthRequestConfirmed(ctx context.Context, id, exchangeToken string) (bool, error)
@@ -73,10 +76,20 @@ func NewPlatformClient() *PlatformClient {
7376
}
7477

7578
func (c *PlatformClient) CreateAuthRequest(ctx context.Context) (*AuthRequest, error) {
76-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/v1/auth/request", nil)
79+
payload := map[string]string{
80+
"actor": actor,
81+
"version": version.Version(),
82+
}
83+
body, err := json.Marshal(payload)
84+
if err != nil {
85+
return nil, fmt.Errorf("failed to marshal request: %w", err)
86+
}
87+
88+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/v1/auth/request", bytes.NewReader(body))
7789
if err != nil {
7890
return nil, fmt.Errorf("failed to create request: %w", err)
7991
}
92+
req.Header.Set("Content-Type", "application/json")
8093

8194
resp, err := c.httpClient.Do(req)
8295
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, "lstk", payload["actor"], "actor should be lstk")
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)