1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/sync/net/BrowserIDAuthHeaderProvider.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,37 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.sync.net; 1.9 + 1.10 +import ch.boye.httpclientandroidlib.Header; 1.11 +import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase; 1.12 +import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; 1.13 +import ch.boye.httpclientandroidlib.message.BasicHeader; 1.14 +import ch.boye.httpclientandroidlib.protocol.BasicHttpContext; 1.15 + 1.16 +/** 1.17 + * An <code>AuthHeaderProvider</code> that returns an Authorization header for 1.18 + * BrowserID assertions in the format expected by a Mozilla Services Token 1.19 + * Server. 1.20 + * <p> 1.21 + * See <a href="http://docs.services.mozilla.com/token/apis.html">http://docs.services.mozilla.com/token/apis.html</a>. 1.22 + */ 1.23 +public class BrowserIDAuthHeaderProvider implements AuthHeaderProvider { 1.24 + protected final String assertion; 1.25 + 1.26 + public BrowserIDAuthHeaderProvider(String assertion) { 1.27 + if (assertion == null) { 1.28 + throw new IllegalArgumentException("assertion must not be null."); 1.29 + } 1.30 + 1.31 + this.assertion = assertion; 1.32 + } 1.33 + 1.34 + @Override 1.35 + public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client) { 1.36 + Header header = new BasicHeader("Authorization", "BrowserID " + assertion); 1.37 + 1.38 + return header; 1.39 + } 1.40 +}