Bug 1308337 - Pre: Read hashedFxaUid from the token server r=nalexander
This is what we (and other platforms) use as part of telemetry payloads in place of either
our local FxA Device ID or the sync client ID.
Note that this server API is currently undocumented.
Parameter introduced in https://github.com/mozilla-services/tokenserver/commit/2021994ca4682acde83242ee0b96140a05c7c4f5
MozReview-Commit-ID: 64sY5RZ2ZxK
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/tokenserver/TokenServerClient.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/tokenserver/TokenServerClient.java
@@ -46,26 +46,26 @@ import ch.boye.httpclientandroidlib.mess
* authorization credential. Usually, it used to exchange a public-key
* authorization token that is expensive to validate for a symmetric-key
* authorization that is cheap to validate. For example, we might exchange a
* BrowserID assertion for a HAWK id and key pair.
*/
public class TokenServerClient {
protected static final String LOG_TAG = "TokenServerClient";
- public static final String JSON_KEY_API_ENDPOINT = "api_endpoint";
- public static final String JSON_KEY_CONDITION_URLS = "condition_urls";
- public static final String JSON_KEY_DURATION = "duration";
- public static final String JSON_KEY_ERRORS = "errors";
- public static final String JSON_KEY_ID = "id";
- public static final String JSON_KEY_KEY = "key";
- public static final String JSON_KEY_UID = "uid";
+ private static final String JSON_KEY_API_ENDPOINT = "api_endpoint";
+ private static final String JSON_KEY_CONDITION_URLS = "condition_urls";
+ private static final String JSON_KEY_ERRORS = "errors";
+ private static final String JSON_KEY_ID = "id";
+ private static final String JSON_KEY_KEY = "key";
+ private static final String JSON_KEY_UID = "uid";
+ private static final String JSON_KEY_HASHED_FXA_UID = "hashed_fxa_uid";
- public static final String HEADER_CONDITIONS_ACCEPTED = "X-Conditions-Accepted";
- public static final String HEADER_CLIENT_STATE = "X-Client-State";
+ private static final String HEADER_CONDITIONS_ACCEPTED = "X-Conditions-Accepted";
+ private static final String HEADER_CLIENT_STATE = "X-Client-State";
protected final Executor executor;
protected final URI uri;
public TokenServerClient(URI uri, Executor executor) {
if (uri == null) {
throw new IllegalArgumentException("uri must not be null");
}
@@ -215,27 +215,28 @@ public class TokenServerClient {
throw new TokenServerUnknownServiceException(errorList);
}
// We shouldn't ever get here...
throw new TokenServerException(errorList);
}
try {
- result.throwIfFieldsMissingOrMisTyped(new String[] { JSON_KEY_ID, JSON_KEY_KEY, JSON_KEY_API_ENDPOINT }, String.class);
+ result.throwIfFieldsMissingOrMisTyped(new String[] { JSON_KEY_ID, JSON_KEY_KEY, JSON_KEY_API_ENDPOINT, JSON_KEY_HASHED_FXA_UID }, String.class);
result.throwIfFieldsMissingOrMisTyped(new String[] { JSON_KEY_UID }, Long.class);
} catch (BadRequiredFieldJSONException e ) {
throw new TokenServerMalformedResponseException(null, e);
}
Logger.debug(LOG_TAG, "Successful token response: " + result.getString(JSON_KEY_ID));
return new TokenServerToken(result.getString(JSON_KEY_ID),
result.getString(JSON_KEY_KEY),
result.get(JSON_KEY_UID).toString(),
+ result.getString(JSON_KEY_HASHED_FXA_UID),
result.getString(JSON_KEY_API_ENDPOINT));
}
public static class TokenFetchResourceDelegate extends BaseResourceDelegate {
private final TokenServerClient client;
private final TokenServerClientDelegate delegate;
private final String assertion;
private final String clientState;
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/tokenserver/TokenServerToken.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/tokenserver/TokenServerToken.java
@@ -3,17 +3,19 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.tokenserver;
public class TokenServerToken {
public final String id;
public final String key;
public final String uid;
+ public final String hashedFxaUid;
public final String endpoint;
- public TokenServerToken(String id, String key, String uid, String endpoint) {
+ public TokenServerToken(String id, String key, String uid, String hashedFxaUid, String endpoint) {
this.id = id;
this.key = key;
this.uid = uid;
+ this.hashedFxaUid = hashedFxaUid;
this.endpoint = endpoint;
}
}
\ No newline at end of file
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/tokenserver/test/TestTokenServerClient.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/tokenserver/test/TestTokenServerClient.java
@@ -49,16 +49,17 @@ import static org.junit.Assert.fail;
public class TestTokenServerClient {
public static final String JSON = "application/json";
public static final String TEXT = "text/plain";
public static final String TEST_TOKEN_RESPONSE = "{\"api_endpoint\": \"https://stage-aitc1.services.mozilla.com/1.0/1659259\"," +
"\"duration\": 300," +
"\"id\": \"eySHORTENED\"," +
"\"key\": \"-plSHORTENED\"," +
+ "\"hashed_fxa_uid\": \"rAnD0MU1D\"," +
"\"uid\": 1659259}";
public static final String TEST_CONDITIONS_RESPONSE = "{\"errors\":[{" +
"\"location\":\"header\"," +
"\"description\":\"Need to accept conditions\"," +
"\"condition_urls\":{\"tos\":\"http://url-to-tos.com\"}," +
"\"name\":\"X-Conditions-Accepted\"}]," +
"\"status\":\"error\"}";