private String buildOAuth1Header(DbxOAuth1AccessToken token) { StringBuilder buf = new StringBuilder(); buf.append("OAuth oauth_version=\"1.0\", oauth_signature_method=\"PLAINTEXT\""); buf.append(", oauth_consumer_key=\"").append(encode(this.appInfo.getKey())).append("\""); buf.append(", oauth_token=\"").append(encode(token.getKey())).append("\""); buf.append(", oauth_signature=\"").append(encode(this.appInfo.getSecret())).append("&").append(encode(token.getSecret())).append("\""); return buf.toString(); }
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) ); }
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); } } ); }