Skip to content

feat: Add telemetry support for flutter windows#829

Draft
NandanPrabhu wants to merge 1 commit into
beta-release/v2.1.0from
feat/add-instrumentation-flutter-windows
Draft

feat: Add telemetry support for flutter windows#829
NandanPrabhu wants to merge 1 commit into
beta-release/v2.1.0from
feat/add-instrumentation-flutter-windows

Conversation

@NandanPrabhu
Copy link
Copy Markdown
Contributor

@NandanPrabhu NandanPrabhu commented May 13, 2026

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

📋 Changes

Adds the Auth0-Client instrumentation/telemetry header to the Windows /oauth/token POST request

New — BuildAuth0ClientHeader(name, version) helper (auth0_client.h/cpp):

  • Builds a base64url-encoded JSON payload sent as the Auth0-Client HTTP header:
    {"name":"auth0-flutter","version":"2.1.0","env":{"Windows":"10.0"}}
  • Uses RFC 4648 §5 base64url encoding (URL-safe alphabet, no padding)
  • Detects the real Windows OS version via RtlGetVersion (works correctly on Windows 10+ where GetVersionEx lies)

Modified — Auth0Client class (auth0_client.h/cpp):

  • Constructor now accepts a third auth0ClientHeader string parameter
  • ExchangeCodeForTokens attaches the Auth0-Client header on the token exchange request when the value is non-empty

Modified — LoginWebAuthRequestHandler (login_web_auth_request_handler.cpp):

  • Extracts the _userAgent map (name + version) from Dart method call arguments
  • Calls BuildAuth0ClientHeader(name, version) and passes the result into Auth0Client
  • The Dart layer already sends _userAgent on every WebAuthRequest via the platform interface Request base class — no Dart changes needed

Platform consistency:

Platform env field
iOS/macOS {"iOS":"17.0","swift":"5.9"}
Android {"android":"34"}
Windows {"Windows":"10.0"}

All platforms use the same JSON schema and base64url encoding.

📎 References

  • Auth0.swift telemetry implementation: Auth0/Telemetry.swift (sets Auth0-Client header on every request)
  • Dart-side _userAgent source: auth0_flutter_platform_interface/lib/src/request/request.dart:16
  • RFC 4648 §5 (base64url encoding): https://datatracker.ietf.org/doc/html/rfc4648#section-5

🎯 Testing

Automated (5 unit tests in auth0_client_telemetry_test.cpp):

  • IsNotEmpty — header is always produced
  • ContainsNoBase64Padding — no = padding characters
  • ContainsNoStandardBase64Chars+-, /_
  • DecodestoValidJson — decoded payload contains expected name, version, env, and Windows keys
  • EmptyNameAndVersionStillProducesValidHeader — graceful fallback when Dart doesn't supply agent info

Manual verification:

  1. Run the example app on Windows, complete a login flow
  2. Check Auth0 tenant logs to confirm the Auth0-Client header is present on the /oauth/token request
  3. Decode the header value (base64url → JSON) and verify it contains the correct SDK name, version, and Windows OS version

Mirrors the telemetry pattern used by Auth0.swift / iOS:

- auth0_client.h/cpp: new BuildAuth0ClientHeader(name, version) helper
  that builds a base64url-encoded JSON payload:
    {"name":"auth0-flutter","version":"x.y.z","env":{"Windows":"10.0"}}
  and attaches it as the Auth0-Client header on every /oauth/token POST.
  Windows version is read via RtlGetVersion (works on Windows 10+,
  unlike the deprecated GetVersionEx).

- login_web_auth_request_handler.cpp: extracts the _userAgent map
  (name + version) sent from the Dart layer, builds the header value,
  and passes it through to Auth0Client.

- auth0_client_telemetry_test.cpp: unit tests for BuildAuth0ClientHeader
  covering encoding correctness, absence of padding/standard-base64-chars,
  and decodable JSON structure.

The Dart side already sends _userAgent in every WebAuthRequest (see
auth0_flutter_platform_interface/lib/src/request/request.dart:16).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant