Skip to content

feat(analytics): add service account authentication support#88

Open
lajohn4747 wants to merge 10 commits into
masterfrom
johnla-multi-564-add-service-account-support-to-java-sdk
Open

feat(analytics): add service account authentication support#88
lajohn4747 wants to merge 10 commits into
masterfrom
johnla-multi-564-add-service-account-support-to-java-sdk

Conversation

@lajohn4747

@lajohn4747 lajohn4747 commented Jun 22, 2026

Copy link
Copy Markdown

Summary

Add service account authentication for /import endpoint and feature flags.

  • Add ServiceAccountCredential class with field validation
  • Update MixpanelAPI to support service account auth for /import
  • Add service account support to feature flags (BaseFlagsConfig, providers)
  • Automatically inject credentials from MixpanelAPI Builder into flags configs
  • Add basic tests for auth methods and backward compatibility
  • Update README with usage examples

@lajohn4747
lajohn4747 requested review from a team and ketanmixpanel June 22, 2026 20:18
@linear-code

linear-code Bot commented Jun 22, 2026

Copy link
Copy Markdown

MULTI-564

@lajohn4747
lajohn4747 marked this pull request as draft June 23, 2026 00:36
@lajohn4747 lajohn4747 changed the title Support Service Account Authentication feat(analytics): add service account authentication support Jun 23, 2026
…ous class after builder

Java doesn't support creating anonymous subclasses from builder.build() return values.
Changed to use local class declarations within test methods to override sendImportData
and sendData for testing purposes.
The Builder constructor is private so tests cannot subclass MixpanelAPI
via Builder pattern. Simplified tests to just verify API construction
with and without credentials works correctly.
@lajohn4747
lajohn4747 marked this pull request as ready for review June 23, 2026 03:10
@lajohn4747
lajohn4747 requested review from efahk and tylerjroach June 23, 2026 03:10
@lajohn4747
lajohn4747 marked this pull request as draft June 30, 2026 21:59
@lajohn4747 lajohn4747 closed this Jul 13, 2026
@lajohn4747 lajohn4747 reopened this Jul 20, 2026
@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The change is additive and opt-in; all existing call sites pass null for credentials and follow the token-based path unchanged.

Backward compatibility is maintained through overloaded constructors, and input validation in ServiceAccountCredential catches the most dangerous misuse at construction time.

No files require special attention.

Important Files Changed

Filename Overview
src/main/java/com/mixpanel/mixpanelapi/ServiceAccountCredential.java New credential holder with field validation including colon-in-username guard for RFC 7617 compliance.
src/main/java/com/mixpanel/mixpanelapi/MixpanelAPI.java Threads credentials through Builder and all constructors; sendImportData correctly switches between token and service-account Basic Auth and appends project_id.
src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/BaseFlagsProvider.java Stores credentials; getWithAuth correctly switches auth header between service-account and token modes.
src/test/java/com/mixpanel/mixpanelapi/MixpanelAPITest.java Adds credential validation tests and Builder tests; testServiceAccountNotUsedForTracking and testBuilderWithCredentials are redundant duplicates.
src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/LocalFlagsProvider.java Adds project_id to definitions URL when credentials present; delegates to new 4-arg super constructor.
src/main/java/com/mixpanel/mixpanelapi/featureflags/provider/RemoteFlagsProvider.java Adds project_id to flags URL when credentials present; mirrors LocalFlagsProvider pattern.
README.md Adds service account usage examples; README notes now correctly describe token still present on flag URLs.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant App
    participant Builder as MixpanelAPI.Builder
    participant API as MixpanelAPI
    participant Flags as Flags Providers
    participant MP as Mixpanel Server

    App->>Builder: credentials(ServiceAccountCredential)
    Builder->>API: build()
    API->>Flags: new Provider(..., credentials)
    App->>API: deliver(import messages)
    API->>MP: "POST /import?project_id=X"
    App->>Flags: getFlags()
    Flags->>MP: "GET /flags?token=T&project_id=X"
    MP-->>Flags: flag definitions
    Flags-->>App: flag value
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant App
    participant Builder as MixpanelAPI.Builder
    participant API as MixpanelAPI
    participant Flags as Flags Providers
    participant MP as Mixpanel Server

    App->>Builder: credentials(ServiceAccountCredential)
    Builder->>API: build()
    API->>Flags: new Provider(..., credentials)
    App->>API: deliver(import messages)
    API->>MP: "POST /import?project_id=X"
    App->>Flags: getFlags()
    Flags->>MP: "GET /flags?token=T&project_id=X"
    MP-->>Flags: flag definitions
    Flags-->>App: flag value
Loading

Reviews (2): Last reviewed commit: "Handle greptile comments" | Re-trigger Greptile

Comment thread README.md
@lajohn4747
lajohn4747 marked this pull request as ready for review July 20, 2026 21:50
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