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.sync.net; michael@0: michael@0: import ch.boye.httpclientandroidlib.Header; michael@0: import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase; michael@0: import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; michael@0: import ch.boye.httpclientandroidlib.message.BasicHeader; michael@0: import ch.boye.httpclientandroidlib.protocol.BasicHttpContext; michael@0: michael@0: /** michael@0: * An AuthHeaderProvider that returns an Authorization header for michael@0: * BrowserID assertions in the format expected by a Mozilla Services Token michael@0: * Server. michael@0: *

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