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);
}
}
);
}