Skip to content

Commit 2b2dce9

Browse files
committed
Merge pull request #21 from auth0/add-telemetry-to-constructor
Customise Telemetry info
2 parents 566022d + 39367f4 commit 2b2dce9

3 files changed

Lines changed: 32 additions & 10 deletions

File tree

auth0/src/main/java/com/auth0/Auth0.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ public class Auth0 {
4848

4949
/**
5050
* Creates a new object using clientId & domain
51+
*
5152
* @param clientId of your Auth0 application
52-
* @param domain of your Auth0 account
53+
* @param domain of your Auth0 account
5354
*/
5455
public Auth0(String clientId, String domain) {
5556
this(clientId, null, domain, null);
5657
}
5758

5859
/**
5960
* Creates a new object using clientId & domain
61+
*
6062
* @param clientId of your Auth0 application
61-
* @param domain of your Auth0 account
63+
* @param domain of your Auth0 account
6264
*/
6365
public Auth0(String clientId, String clientSecret, String domain) {
6466
this(clientId, clientSecret, domain, null);
@@ -68,9 +70,10 @@ public Auth0(String clientId, String clientSecret, String domain) {
6870
* Creates a new object using clientId, domain and configuration domain.
6971
* Useful when using a on-premise auth0 server that is not in the public cloud,
7072
* otherwise we recommend using the constructor {@link #Auth0(String, String)}
71-
* @param clientId of your Auth0 application
72-
* @param clientSecret of your Auth0 application. It can be null, specially if used for an Android application
73-
* @param domain of your Auth0 account
73+
*
74+
* @param clientId of your Auth0 application
75+
* @param clientSecret of your Auth0 application. It can be null, specially if used for an Android application
76+
* @param domain of your Auth0 account
7477
* @param configurationDomain where Auth0's configuration will be fetched. By default is Auth0 public cloud
7578
*/
7679
public Auth0(String clientId, String clientSecret, String domain, String configurationDomain) {
@@ -133,6 +136,16 @@ public Telemetry getTelemetry() {
133136
return telemetry;
134137
}
135138

139+
140+
/**
141+
* Setter for the Telemetry to send in every request to Auth0.
142+
*
143+
* @param telemetry to send in every request to Auth0
144+
*/
145+
public void setTelemetry(Telemetry telemetry) {
146+
this.telemetry = telemetry;
147+
}
148+
136149
/**
137150
* Avoid sending telemetry in every request to Auth0
138151
*/
@@ -148,7 +161,7 @@ private String resolveConfiguration(String configurationDomain, String domainUrl
148161
if (host.endsWith(DOT_AUTH0_DOT_COM)) {
149162
String[] parts = host.split("\\.");
150163
if (parts.length > 3) {
151-
url = "https://cdn." + parts[parts.length-3] + DOT_AUTH0_DOT_COM;
164+
url = "https://cdn." + parts[parts.length - 3] + DOT_AUTH0_DOT_COM;
152165
} else {
153166
url = AUTH0_US_CDN_URL;
154167
}

auth0/src/main/java/com/auth0/BuildConfig.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.auth0;
22

3-
abstract class BuildConfig {
4-
5-
private BuildConfig() {}
3+
public abstract class BuildConfig {
64

75
/**
86
* Version of auth0-java

auth0/src/test/java/com/auth0/Auth0Test.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@
2525
package com.auth0;
2626

2727
import com.auth0.authentication.AuthenticationAPIClient;
28+
import com.auth0.util.Telemetry;
2829

2930
import org.junit.Test;
3031

3132
import static org.hamcrest.Matchers.equalTo;
3233
import static org.hamcrest.Matchers.is;
3334
import static org.hamcrest.Matchers.notNullValue;
3435
import static org.hamcrest.Matchers.nullValue;
35-
import static org.junit.Assert.*;
36+
import static org.junit.Assert.assertThat;
3637

3738
public class Auth0Test {
3839

3940
private static final String CLIENT_ID = "CLIENT_ID";
41+
private static final String CLIENT_SECRET = "CLIENT_SECRET";
42+
private static final String CONFIGURATION_DOMAIN = "CONFIGURATION_DOMAIN";
4043
private static final String DOMAIN = "samples.auth0.com";
4144
private static final String CONFIG_DOMAIN_CUSTOM = "config.mydomain.com";
4245
private static final String EU_DOMAIN = "samples.eu.auth0.com";
@@ -112,4 +115,12 @@ public void shouldNotReturnTelemetryWhenExplicitlyDisabledThem() throws Exceptio
112115
auth0.doNotSendTelemetry();
113116
assertThat(auth0.getTelemetry(), is(nullValue()));
114117
}
118+
119+
@Test
120+
public void shouldSetCustomTelemetry() throws Exception {
121+
Telemetry customTelemetry = new Telemetry("custom", "9.9.9", "1.1.1");
122+
Auth0 auth0 = new Auth0(CLIENT_ID, DOMAIN);
123+
auth0.setTelemetry(customTelemetry);
124+
assertThat(auth0.getTelemetry(), is(equalTo(customTelemetry)));
125+
}
115126
}

0 commit comments

Comments
 (0)