Skip to content

User-Agent reverts to "Anonymous" for token-authenticated clients constructed without a username #3

Description

@duckduckgrayduck

How to replicate:

from squarelet import SquareletClient

good = SquareletClient(base_uri=BASE_URI, username=USER, password=PW)

# good UA -> "... <username>"   (correct)

rebuilt = SquareletClient(base_uri=BASE_URI)   # no creds -> "... Anonymous"
rebuilt.refresh_token = good.refresh_token
rebuilt._set_tokens()

print(rebuilt.session.headers["User-Agent"])       # "... Anonymous"  <-- bug
print(rebuilt.session.headers["Authorization"])    # valid Bearer token

Proposed fix

Rebuild the UA deterministically from a captured base on every auth-state change, and when there's no local username, resolve one from users/me/ (cached). This labels any authenticated client correctly regardless of how it acquired its token.

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions