summaryrefslogtreecommitdiffstats
path: root/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20LoginDelegate.java
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20LoginDelegate.java')
-rw-r--r--mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20LoginDelegate.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20LoginDelegate.java b/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20LoginDelegate.java
new file mode 100644
index 000000000..0266a6eab
--- /dev/null
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccount20LoginDelegate.java
@@ -0,0 +1,36 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.background.fxa;
+
+import org.mozilla.gecko.sync.ExtendedJSONObject;
+import org.mozilla.gecko.sync.Utils;
+
+import java.io.UnsupportedEncodingException;
+import java.security.GeneralSecurityException;
+
+/**
+ * An abstraction around providing an email and authorization token to the auth
+ * server.
+ */
+public class FxAccount20LoginDelegate {
+ protected final byte[] emailUTF8;
+ protected final byte[] authPW;
+
+ public FxAccount20LoginDelegate(byte[] emailUTF8, byte[] quickStretchedPW) throws UnsupportedEncodingException, GeneralSecurityException {
+ this.emailUTF8 = emailUTF8;
+ this.authPW = FxAccountUtils.generateAuthPW(quickStretchedPW);
+ }
+
+ public ExtendedJSONObject getCreateBody() throws FxAccountClientException {
+ final ExtendedJSONObject body = new ExtendedJSONObject();
+ try {
+ body.put("email", new String(emailUTF8, "UTF-8"));
+ body.put("authPW", Utils.byte2Hex(authPW));
+ return body;
+ } catch (UnsupportedEncodingException e) {
+ throw new FxAccountClientException(e);
+ }
+ }
+}