michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.background.fxa; michael@0: michael@0: import java.io.UnsupportedEncodingException; michael@0: import java.security.GeneralSecurityException; michael@0: michael@0: import org.json.simple.JSONObject; michael@0: import org.mozilla.gecko.background.fxa.FxAccountClient10.CreateDelegate; michael@0: import org.mozilla.gecko.sync.Utils; michael@0: michael@0: /** michael@0: * An abstraction around providing an email and authorization token to the auth michael@0: * server. michael@0: */ michael@0: public class FxAccount20LoginDelegate implements CreateDelegate { michael@0: protected final byte[] emailUTF8; michael@0: protected final byte[] authPW; michael@0: michael@0: public FxAccount20LoginDelegate(byte[] emailUTF8, byte[] quickStretchedPW) throws UnsupportedEncodingException, GeneralSecurityException { michael@0: this.emailUTF8 = emailUTF8; michael@0: this.authPW = FxAccountUtils.generateAuthPW(quickStretchedPW); michael@0: } michael@0: michael@0: @SuppressWarnings("unchecked") michael@0: @Override michael@0: public JSONObject getCreateBody() throws FxAccountClientException { michael@0: final JSONObject body = new JSONObject(); michael@0: try { michael@0: body.put("email", new String(emailUTF8, "UTF-8")); michael@0: body.put("authPW", Utils.byte2Hex(authPW)); michael@0: return body; michael@0: } catch (UnsupportedEncodingException e) { michael@0: throw new FxAccountClientException(e); michael@0: } michael@0: } michael@0: }