-
Notifications
You must be signed in to change notification settings - Fork 39
feat(analytics): add service account authentication support #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lajohn4747
wants to merge
10
commits into
master
Choose a base branch
from
johnla-multi-564-add-service-account-support-to-java-sdk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
df20db1
Support Service Account Authentication
lajohn4747 d3ca79d
Handle flags
lajohn4747 2d2aab1
Support feature flags and offer backward compat
lajohn4747 bc9339e
include token
lajohn4747 b77c3aa
fix: use proper local class syntax in tests instead of invalid anonym…
lajohn4747 a06ec36
fix: simplify service account tests to avoid private constructor
lajohn4747 d187e1f
Fix the mp_lib to jdk
lajohn4747 f3dc3be
Revert tests
lajohn4747 eb0b8b9
Simplify tests
lajohn4747 93668ec
Handle greptile comments
lajohn4747 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/com/mixpanel/mixpanelapi/ServiceAccountCredential.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package com.mixpanel.mixpanelapi; | ||
|
|
||
| /** | ||
| * Encapsulates service account credentials for server-to-server authentication. | ||
| * <p> | ||
| * <strong>Recommended:</strong> Service account authentication is the preferred method for | ||
| * server-side integrations. Service accounts provide enhanced security by using unique | ||
| * username/secret pairs instead of relying solely on the project token for authentication. | ||
| * </p> | ||
| * <p> | ||
| * Service accounts use a project ID, username, and secret for authentication. | ||
| * This class ensures all required credential fields are provided together. | ||
| * </p> | ||
| * <p> | ||
| * Service account credentials are only used for the /import endpoint (and feature flags). | ||
| * Regular event tracking operations (track, people updates, group updates) use the project | ||
| * token provided in the message payload. | ||
| * </p> | ||
| * | ||
| * @see MixpanelAPI.Builder#credentials(ServiceAccountCredential) | ||
| */ | ||
| public final class ServiceAccountCredential { | ||
| private final long projectId; | ||
| private final String username; | ||
| private final String secret; | ||
|
|
||
| /** | ||
| * Creates a new ServiceAccountCredential. | ||
| * | ||
| * @param projectId the Mixpanel project ID | ||
| * @param username the service account username | ||
| * @param secret the service account secret | ||
| * @throws IllegalArgumentException if projectId is invalid, username/secret are null or empty, | ||
| * or username contains a colon | ||
| */ | ||
| public ServiceAccountCredential(long projectId, String username, String secret) { | ||
| if (projectId <= 0) { | ||
| throw new IllegalArgumentException("projectId must be greater than zero"); | ||
| } | ||
| if (username == null || username.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("username cannot be null or empty"); | ||
| } | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
| // The username is used as the user-id in an HTTP Basic Auth header (username:secret). | ||
| // Per RFC 7617 the user-id must not contain a colon, otherwise the server treats | ||
| // everything before the first colon as the username, causing a silent auth failure. | ||
| if (username.contains(":")) { | ||
| throw new IllegalArgumentException("username cannot contain a colon (':')"); | ||
| } | ||
| if (secret == null || secret.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("secret cannot be null or empty"); | ||
| } | ||
|
|
||
| this.projectId = projectId; | ||
| this.username = username; | ||
| this.secret = secret; | ||
| } | ||
|
|
||
| /** | ||
| * @return the Mixpanel project ID | ||
| */ | ||
| public long getProjectId() { | ||
| return projectId; | ||
| } | ||
|
|
||
| /** | ||
| * @return the service account username | ||
| */ | ||
| public String getUsername() { | ||
| return username; | ||
| } | ||
|
|
||
| /** | ||
| * @return the service account secret | ||
| */ | ||
| public String getSecret() { | ||
| return secret; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.