The oauth client exchanges Firefox Account assertions for oauth token grants. The client_id is assumed to have the "canGrant" capability on the oauth endpoint. ========d1a25c8233Author: Nick Alexander <nalexander@mozilla.com> Bug 1117829 - Part 3: Add FxA oauth and profile clients. ========6c52ce9b53Author: Nick Alexander <nalexander@mozilla.com> Date: Mon Aug 18 13:53:56 2014 -0700 Bug 1117829 - Part 2: Support remote verifier v1 and v2. ========679e972d2cAuthor: Nick Alexander <nalexander@mozilla.com> Date: Mon Aug 18 11:52:45 2014 -0700 Bug 1117829 - Part 1: Generalize bearer token auth header providers. ========b55a14fe88Author: Nick Alexander <nalexander@mozilla.com> Date: Mon Aug 18 13:54:46 2014 -0700 Bug 1117829 - Pre: Add static methods for cross-class testing. ========5576662dd3Author: Nick Alexander <nalexander@mozilla.com> Date: Mon Aug 18 11:42:45 2014 -0700 Bug 1117829 - Pre: Fix debug printing of JWT structures.
96 lines
3.1 KiB
Java
96 lines
3.1 KiB
Java
/* 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.browserid.verifier;
|
|
|
|
import java.io.IOException;
|
|
import java.net.URI;
|
|
import java.security.GeneralSecurityException;
|
|
|
|
import org.mozilla.gecko.background.common.log.Logger;
|
|
import org.mozilla.gecko.browserid.verifier.BrowserIDVerifierException.BrowserIDVerifierErrorResponseException;
|
|
import org.mozilla.gecko.browserid.verifier.BrowserIDVerifierException.BrowserIDVerifierMalformedResponseException;
|
|
import org.mozilla.gecko.sync.ExtendedJSONObject;
|
|
import org.mozilla.gecko.sync.net.BaseResourceDelegate;
|
|
import org.mozilla.gecko.sync.net.Resource;
|
|
import org.mozilla.gecko.sync.net.SyncResponse;
|
|
|
|
import ch.boye.httpclientandroidlib.HttpResponse;
|
|
import ch.boye.httpclientandroidlib.client.ClientProtocolException;
|
|
|
|
public abstract class AbstractBrowserIDRemoteVerifierClient implements BrowserIDVerifierClient {
|
|
public static final String LOG_TAG = AbstractBrowserIDRemoteVerifierClient.class.getSimpleName();
|
|
|
|
protected static class RemoteVerifierResourceDelegate extends BaseResourceDelegate {
|
|
private final BrowserIDVerifierDelegate delegate;
|
|
|
|
protected RemoteVerifierResourceDelegate(Resource resource, BrowserIDVerifierDelegate delegate) {
|
|
super(resource);
|
|
this.delegate = delegate;
|
|
}
|
|
|
|
@Override
|
|
public String getUserAgent() {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public void handleHttpResponse(HttpResponse response) {
|
|
SyncResponse res = new SyncResponse(response);
|
|
int statusCode = res.getStatusCode();
|
|
Logger.debug(LOG_TAG, "Got response with status code " + statusCode + ".");
|
|
|
|
if (statusCode != 200) {
|
|
delegate.handleError(new BrowserIDVerifierErrorResponseException("Expected status code 200."));
|
|
return;
|
|
}
|
|
|
|
ExtendedJSONObject o = null;
|
|
try {
|
|
o = res.jsonObjectBody();
|
|
} catch (Exception e) {
|
|
delegate.handleError(new BrowserIDVerifierMalformedResponseException(e));
|
|
return;
|
|
}
|
|
|
|
String status = o.getString("status");
|
|
if ("failure".equals(status)) {
|
|
delegate.handleFailure(o);
|
|
return;
|
|
}
|
|
|
|
if (!("okay".equals(status))) {
|
|
delegate.handleError(new BrowserIDVerifierMalformedResponseException("Expected status okay, got '" + status + "'."));
|
|
return;
|
|
}
|
|
|
|
delegate.handleSuccess(o);
|
|
}
|
|
|
|
@Override
|
|
public void handleTransportException(GeneralSecurityException e) {
|
|
Logger.warn(LOG_TAG, "Got transport exception.", e);
|
|
delegate.handleError(e);
|
|
}
|
|
|
|
@Override
|
|
public void handleHttpProtocolException(ClientProtocolException e) {
|
|
Logger.warn(LOG_TAG, "Got protocol exception.", e);
|
|
delegate.handleError(e);
|
|
}
|
|
|
|
@Override
|
|
public void handleHttpIOException(IOException e) {
|
|
Logger.warn(LOG_TAG, "Got IO exception.", e);
|
|
delegate.handleError(e);
|
|
}
|
|
}
|
|
|
|
protected final URI verifierUri;
|
|
|
|
public AbstractBrowserIDRemoteVerifierClient(URI verifierUri) {
|
|
this.verifierUri = verifierUri;
|
|
}
|
|
}
|