@Override protected void addAuthHeaders(List<HttpRequestor.Header> headers) { DbxRequestUtil.addAuthHeader(headers, accessToken); if (memberId != null) { DbxRequestUtil.addSelectUserHeader(headers, memberId); } if (adminId != null) { DbxRequestUtil.addSelectAdminHeader(headers, adminId); } }
@Override protected void addAuthHeaders(List<HttpRequestor.Header> headers) { DbxRequestUtil.addBasicAuthHeader(headers, key, secret); }
public static String buildUrlWithParams(/*@Nullable*/String userLocale, String host, String path, /*@Nullable*/String/*@Nullable*/[] params) { return buildUri(host, path) + "?" + encodeUrlParams(userLocale, params); }
public static <T> T doPost(DbxRequestConfig requestConfig, String accessToken, String sdkUserAgentIdentifier, String host, String path, /*@Nullable*/String/*@Nullable*/[] params, /*@Nullable*/List<HttpRequestor.Header> headers, ResponseHandler<T> handler) throws DbxException { headers = copyHeaders(headers); headers = addAuthHeader(headers, accessToken); return doPostNoAuth(requestConfig, sdkUserAgentIdentifier, host, path, params, headers, handler); }
/** * Convenience function for making HTTP PUT requests. */ public static HttpRequestor.Uploader startPut(DbxRequestConfig requestConfig, String accessToken, String sdkUserAgentIdentifier, String host, String path, /*@Nullable*/String/*@Nullable*/[] params, /*@Nullable*/List<HttpRequestor.Header> headers) throws NetworkIOException { headers = copyHeaders(headers); headers = addUserAgentHeader(headers, requestConfig, sdkUserAgentIdentifier); headers = addAuthHeader(headers, accessToken); String url = buildUrlWithParams(requestConfig.getUserLocale(), host, path, params); try { return requestConfig.getHttpRequestor().startPut(url, headers); } catch (IOException ex) { throw new NetworkIOException(ex); } }
public <ArgT> HttpRequestor.Uploader uploadStyle(String host, String path, ArgT arg, boolean noAuth, StoneSerializer<ArgT> argSerializer) throws DbxException { String uri = DbxRequestUtil.buildUri(host, path); List<HttpRequestor.Header> headers = new ArrayList<HttpRequestor.Header>(); if (!noAuth) { addAuthHeaders(headers); } addUserLocaleHeader(headers, requestConfig); addPathRootHeader(headers, this.pathRoot); headers.add(new HttpRequestor.Header("Content-Type", "application/octet-stream")); headers = DbxRequestUtil.addUserAgentHeader(headers, requestConfig, USER_AGENT_ID); headers.add(new HttpRequestor.Header("Dropbox-API-Arg", headerSafeJson(argSerializer, arg))); try { return requestConfig.getHttpRequestor().startPost(uri, headers); } catch (IOException ex) { throw new NetworkIOException(ex); } }
private DbxAuthFinish finish(String code, String redirectUri, final String state) throws DbxException { if (code == null) throw new NullPointerException("code"); Map<String, String> params = new HashMap<String, String>(); params.put("grant_type", "authorization_code"); params.put("code", code); params.put("locale", requestConfig.getUserLocale()); if (redirectUri != null) { params.put("redirect_uri", redirectUri); } List<HttpRequestor.Header> headers = new ArrayList<HttpRequestor.Header>(); DbxRequestUtil.addBasicAuthHeader(headers, appInfo.getKey(), appInfo.getSecret()); return DbxRequestUtil.doPostNoAuth( requestConfig, DbxRawClientV2.USER_AGENT_ID, appInfo.getHost().getApi(), "oauth2/token", DbxRequestUtil.toParamsArray(params), headers, new DbxRequestUtil.ResponseHandler<DbxAuthFinish>() { @Override public DbxAuthFinish handle(HttpRequestor.Response response) throws DbxException { if (response.getStatusCode() != 200) { throw DbxRequestUtil.unexpectedStatus(response); } return DbxRequestUtil.readJsonFromResponse(DbxAuthFinish.Reader, response) .withUrlState(state); } } ); }
/** * Convenience function for making HTTP POST requests. Like startPostNoAuth but takes byte[] instead of params. */ public static HttpRequestor.Response startPostRaw(DbxRequestConfig requestConfig, String sdkUserAgentIdentifier, String host, String path, byte[] body, /*@Nullable*/List<HttpRequestor.Header> headers) throws NetworkIOException { String uri = buildUri(host, path); headers = copyHeaders(headers); headers = addUserAgentHeader(headers, requestConfig, sdkUserAgentIdentifier); headers.add(new HttpRequestor.Header("Content-Length", Integer.toString(body.length))); try { HttpRequestor.Uploader uploader = requestConfig.getHttpRequestor().startPost(uri, headers); try { uploader.upload(body); return uploader.finish(); } finally { uploader.close(); } } catch (IOException ex) { throw new NetworkIOException(ex); } }
addUserLocaleHeader(headers, requestConfig); addPathRootHeader(headers, this.pathRoot);
private String authorizeImpl(Request request) { Map<String, String> params = new HashMap<String, String>(); params.put("client_id", appInfo.getKey()); params.put("response_type", "code"); if (request.redirectUri != null) { params.put("redirect_uri", request.redirectUri); params.put("state", appendCsrfToken(request)); } if (request.requireRole != null) { params.put("require_role", request.requireRole); } if (request.forceReapprove != null) { params.put("force_reapprove", Boolean.toString(request.forceReapprove).toLowerCase()); } if (request.disableSignup != null) { params.put("disable_signup", Boolean.toString(request.disableSignup).toLowerCase()); } return DbxRequestUtil.buildUrlWithParams( requestConfig.getUserLocale(), appInfo.getHost().getWeb(), "oauth2/authorize", DbxRequestUtil.toParamsArray(params) ); }
@Override protected void addAuthHeaders(List<HttpRequestor.Header> headers) { DbxRequestUtil.addAuthHeader(headers, accessToken); }
public static List<HttpRequestor.Header> addUserAgentHeader( /*@Nullable*/List<HttpRequestor.Header> headers, DbxRequestConfig requestConfig, String sdkUserAgentIdentifier ) { if (headers == null) headers = new ArrayList<HttpRequestor.Header>(); headers.add(buildUserAgentHeader(requestConfig, sdkUserAgentIdentifier)); return headers; }
private void startWebAuth(String state) { String path = "1/connect"; Locale locale = Locale.getDefault(); locale = new Locale(locale.getLanguage(), locale.getCountry()); // Web Auth currently does not support desiredUid and only one alreadyAuthUid (param n). // We use first alreadyAuthUid arbitrarily. // Note that the API treats alreadyAuthUid of 0 and not present equivalently. String alreadyAuthedUid = (mAlreadyAuthedUids.length > 0) ? mAlreadyAuthedUids[0] : "0"; String[] params = { "k", mAppKey, "n", alreadyAuthedUid, "api", mApiType, "state", state}; String url = DbxRequestUtil.buildUrlWithParams(locale.toString(), mWebHost, path, params); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); }
/** * Convenience function for making HTTP GET requests. */ public static HttpRequestor.Response startGet(DbxRequestConfig requestConfig, String accessToken, String sdkUserAgentIdentifier, String host, String path, /*@Nullable*/String/*@Nullable*/[] params, /*@Nullable*/List<HttpRequestor.Header> headers) throws NetworkIOException { headers = copyHeaders(headers); headers = addUserAgentHeader(headers, requestConfig, sdkUserAgentIdentifier); headers = addAuthHeader(headers, accessToken); String url = buildUrlWithParams(requestConfig.getUserLocale(), host, path, params); try { return requestConfig.getHttpRequestor().doGet(url, headers); } catch (IOException ex) { throw new NetworkIOException(ex); } }
addAuthHeaders(headers); addUserLocaleHeader(headers, requestConfig); addPathRootHeader(headers, this.pathRoot); headers.add(new HttpRequestor.Header("Dropbox-API-Arg", headerSafeJson(argSerializer, arg))); headers.add(new HttpRequestor.Header("Content-Type", ""));