Skip to content

Commit 8d913c1

Browse files
author
Karl Rieb
committed
Fix BadRequest errors when using DbxWebAuth and custom state (DbxWebAuth.Request.Builder.withState(..)).
Fixes T103763
1 parent f69dd34 commit 8d913c1

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

ChangeLog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
2.0.7 (2016-06-20)
22
---------------------------------------------
33
- Add configureRequest(..) method for simpler subclassing of OkHttpRequestor and OkHttp3Requestor.
4+
- Fix BadRequest error when adding custom state to a DbxWebAuth.Request object.
45

56
2.0.6 (2016-06-20)
67
---------------------------------------------

src/main/java/com/dropbox/core/DbxAuthFinish.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ public String getUserId() {
6666
return urlState;
6767
}
6868

69+
/**
70+
* State is not returned from /oauth2/token call, so we must
71+
* append it after the JSON parsing.
72+
*
73+
* @param urlState Custom state passed into /oauth2/authorize
74+
*/
75+
DbxAuthFinish withUrlState(/*@Nullable*/ String urlState) {
76+
if (this.urlState != null) {
77+
throw new IllegalStateException("Already have URL state.");
78+
}
79+
return new DbxAuthFinish(accessToken, userId, urlState);
80+
}
81+
6982
/**
7083
* For JSON parsing.
7184
*/

src/main/java/com/dropbox/core/DbxWebAuth.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ private DbxAuthFinish finish(String code) throws DbxException {
369369
return finish(code, null, null);
370370
}
371371

372-
private DbxAuthFinish finish(String code, String redirectUri, String state) throws DbxException {
372+
private DbxAuthFinish finish(String code, String redirectUri, final String state) throws DbxException {
373373
if (code == null) throw new NullPointerException("code");
374374

375375
Map<String, String> params = new HashMap<String, String>();
@@ -379,7 +379,6 @@ private DbxAuthFinish finish(String code, String redirectUri, String state) thro
379379

380380
if (redirectUri != null) {
381381
params.put("redirect_uri", redirectUri);
382-
params.put("state", state);
383382
}
384383

385384
List<HttpRequestor.Header> headers = new ArrayList<HttpRequestor.Header>();
@@ -398,7 +397,8 @@ public DbxAuthFinish handle(HttpRequestor.Response response) throws DbxException
398397
if (response.getStatusCode() != 200) {
399398
throw DbxRequestUtil.unexpectedStatus(response);
400399
}
401-
return DbxRequestUtil.readJsonFromResponse(DbxAuthFinish.Reader, response);
400+
return DbxRequestUtil.readJsonFromResponse(DbxAuthFinish.Reader, response)
401+
.withUrlState(state);
402402
}
403403
}
404404
);

0 commit comments

Comments
 (0)