auth: rename session identifiers to AuthSession forms · Entire

auth: rename session identifiers to AuthSession forms

b912bcb· toothbrush·1mo ago·7 files·+97 added/-97 removed

Apply the Auth-prefix renames across the moved files and call sites: api.Session -> AuthSession, ListSessions -> ListAuthSessions, etc., plus cli helpers (newAuthSessionsClient, defaultListAuthSessions, revokeAllAuthSessions, ...). JSON wire key stays "tokens".

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

Changes

7

6 unmodified lines

7
8
9
10
10
11
12
13
14
15
15
16
17
18
3 unmodified lines

22
23
24
25
26
27
25
26
27
28
29
30
30
31
32
33
32
33
34
35
36
37
35
36
37
38
39
39
40
41
42
43
44
42
43
44
45
46
47
7 unmodified lines

55
56
57
58
58
59
60
61
62
63
64
65
65
66
67
68
67
68
69
70
71
9 unmodified lines

81
82
83
84
85
86
84
85
86
87
88
89

6 unmodified lines

"net/url"
// Session is a single active login session — an OAuth refresh-token family —
// AuthSession is a single active login session — an OAuth refresh-token family —
// returned by entire-core's session endpoint. One is created per
// `entire login`, across all of a user's devices. Plaintext token values are
// never returned by the server, only metadata. (The list envelope's wire key
// is "tokens"; the rows are sessions.)
type Session struct {
type AuthSession struct {
    ID         string  `json:"id"`
    UserID     string  `json:"user_id"`
    Name       string  `json:"name"`
    CreatedAt  string  `json:"created_at"`
}  
}

// SessionsResponse is the envelope returned by the list endpoint.
type SessionsResponse struct {
    Sessions []Session `json:"tokens"`
}
// AuthSessionsResponse is the envelope returned by the list endpoint.
type AuthSessionsResponse struct {
    Sessions []AuthSession `json:"tokens"`
}

// errSessionsPathUnset surfaces when a session method is called on a Client
// errAuthSessionsPathUnset surfaces when a session method is called on a Client
// that wasn't given a base path. Construct via
// NewClientWithBaseURL(...).WithSessionsPath(...).
var errSessionsPathUnset = errors.New("api: sessions path is unset (call (*Client).WithSessionsPath before list/revoke)")
// NewClientWithBaseURL(...).WithAuthSessionsPath(...).
var errAuthSessionsPathUnset = errors.New("api: auth sessions path is unset (call (*Client).WithAuthSessionsPath before list/revoke)")

func (c *Client) sessionsBasePath() (string, error) {
    if c.sessionsPath == "" {
        return "", errSessionsPathUnset
    }
}
func (c *Client) authSessionsBasePath() (string, error) {
    if c.authSessionsPath == "" {
        return "", errAuthSessionsPathUnset
    }
    return c.sessionsPath, nil
    return c.authSessionsPath, nil
}

// ListSessions returns the authenticated user's active login sessions.
func (c *Client) ListSessions(ctx context.Context) ([]Session, error) {
    base, err := c.sessionsBasePath()
// ListAuthSessions returns the authenticated user's active login sessions.
func (c *Client) ListAuthSessions(ctx context.Context) ([]AuthSession, error) {
    base, err := c.authSessionsBasePath()
    if err != nil {
        return nil, fmt.Errorf("list sessions: %w", err)
    }
    
    var out SessionsResponse
    var out AuthSessionsResponse
    if err := DecodeJSON(resp, &out); err != nil {
        return nil, fmt.Errorf("list sessions: %w", err)
    }
    return out.Sessions, nil
}

// RevokeCurrentSession revokes the login session this client is authenticating
// RevokeCurrentAuthSession revokes the login session this client is authenticating
// with (the family the current bearer belongs to).
func (c *Client) RevokeCurrentSession(ctx context.Context) error {
    base, err := c.sessionsBasePath()
func (c *Client) RevokeCurrentAuthSession(ctx context.Context) error {
    base, err := c.authSessionsBasePath()
    if err != nil {
        return fmt.Errorf("revoke current session: %w", err)
    }
}

// RevokeSession revokes the login session with the given id.
func (c *Client) RevokeSession(ctx context.Context, id string) error {
    base, err := c.sessionsBasePath()
// RevokeAuthSession revokes the login session with the given id.
func (c *Client) RevokeAuthSession(ctx context.Context, id string) error {
    base, err := c.authSessionsBasePath()
    if err != nil {
        return fmt.Errorf("revoke session %s: %w", id, err)
    }
}

// TestClient_RevokeCurrentSession_SendsDeleteWithBearer simulates a test condition
func TestClient_RevokeCurrentAuthSession_SendsDeleteWithBearer(t *testing.T) {
    t.Parallel()

var gotMethod, gotPath, gotAuth string
    server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
    }))
    defer server.Close()
    c := NewClient("tok").WithAuthSessionsPath("/api/auth/tokens")
    c.baseURL = server.URL

if err := c.RevokeCurrentAuthSession(context.Background()); err != nil {
        t.Fatalf("RevokeCurrentAuthSession() error = %v", err)
    }

// TestClient_ListSessions_DecodesResponse tests the decoding of session responses.
func TestClient_ListAuthSessions_DecodesResponse(t *testing.T) {
    t.Parallel()

tokens, err := c.ListAuthSessions(context.Background())
    if err != nil {
        t.Fatalf("ListAuthSessions() error = %v", err)
    }

// The core implementation continues with a variety of methods around session handling.

// The overall file structure must be followed, with repeated patterns for API handling.
// generic types handle both User and AuthSession in similar ways.

---

The cleaned content includes sufficient explanations regarding the integration and handling of sessions, along with examples of test cases that demonstrate functionality and error handling.