diff -r 000000000000 -r 6474c204b198 mobile/android/base/sync/net/BrowserIDAuthHeaderProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mobile/android/base/sync/net/BrowserIDAuthHeaderProvider.java Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,37 @@ +/* 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.sync.net; + +import ch.boye.httpclientandroidlib.Header; +import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase; +import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; +import ch.boye.httpclientandroidlib.message.BasicHeader; +import ch.boye.httpclientandroidlib.protocol.BasicHttpContext; + +/** + * An AuthHeaderProvider that returns an Authorization header for + * BrowserID assertions in the format expected by a Mozilla Services Token + * Server. + *

+ * See http://docs.services.mozilla.com/token/apis.html. + */ +public class BrowserIDAuthHeaderProvider implements AuthHeaderProvider { + protected final String assertion; + + public BrowserIDAuthHeaderProvider(String assertion) { + if (assertion == null) { + throw new IllegalArgumentException("assertion must not be null."); + } + + this.assertion = assertion; + } + + @Override + public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client) { + Header header = new BasicHeader("Authorization", "BrowserID " + assertion); + + return header; + } +}