Skip to content

Commit a58bcc9

Browse files
committed
Merge pull request #24 from LuisLoureiro/displayAndStateValues
Display and state parameters for the OAuth2 authorization endpoint.
2 parents 438aee0 + ec4228b commit a58bcc9

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/main/java/com/soundcloud/api/ApiWrapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ public Token extensionGrantType(String grantType, String... scopes) throws IOExc
226226
REDIRECT_URI, mRedirectUri,
227227
CLIENT_ID, mClientId,
228228
RESPONSE_TYPE, CODE);
229-
if (options.length == 2) req.add(SCOPE, options[1]);
229+
if (options.length > 1) req.add(SCOPE, options[1]);
230+
if (options.length > 2) req.add(DISPLAY, options[2]);
231+
if (options.length > 3) req.add(STATE, options[3]);
230232
return getURI(req, false, true);
231233
}
232234

src/main/java/com/soundcloud/api/CloudAPI.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public interface CloudAPI {
2424
String CODE = "code";
2525
String RESPONSE_TYPE = "response_type";
2626
String SCOPE = "scope";
27+
String DISPLAY = "display";
28+
String STATE = "state";
2729

2830
// standard oauth2 grant types
2931
String PASSWORD = "password";
@@ -41,6 +43,7 @@ public interface CloudAPI {
4143
String OAUTH_SCHEME = "oauth";
4244
String VERSION = "1.3.1";
4345
String USER_AGENT = "SoundCloud Java Wrapper ("+VERSION+")";
46+
String POPUP = "popup";
4447

4548
/**
4649
* Request a token using <a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-10#section-4.1.2">
@@ -211,7 +214,7 @@ public interface CloudAPI {
211214
* <li><code>error</code> in case of failure, this contains an error code (most likely
212215
* <code>access_denied</code>).
213216
* </ul>
214-
* @param options auth endpoint to use (leave out for default), requested scope (leave out for default)
217+
* @param options auth endpoint to use (leave out for default), requested scope (leave out for default), display ('popup' for mobile optimized screen) and state.
215218
* @return the URI to open in a browser/WebView etc.
216219
* @see CloudAPI#authorizationCode(String, String...)
217220
*/

src/test/java/com/soundcloud/api/ApiWrapperTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,26 @@ public void shouldIncludeScopeInAuthorizationUrl() throws Exception {
361361
);
362362
}
363363

364+
@Test
365+
public void shouldIncludeDisplayInAuthorizationUrl() throws Exception {
366+
assertThat(
367+
api.authorizationCodeUrl(Endpoints.CONNECT, Token.SCOPE_NON_EXPIRING, CloudAPI.POPUP).toString(),
368+
equalTo("https://soundcloud.com/connect"+
369+
"?redirect_uri=redirect%3A%2F%2Fme&client_id=" + TEST_CLIENT_ID + "&response_type=code&scope=non-expiring"+
370+
"&display=popup")
371+
);
372+
}
373+
374+
@Test
375+
public void shouldIncludeStateInAuthorizationUrl() throws Exception {
376+
assertThat(
377+
api.authorizationCodeUrl(Endpoints.CONNECT, Token.SCOPE_DEFAULT, CloudAPI.POPUP, "stateValue").toString(),
378+
equalTo("https://soundcloud.com/connect"+
379+
"?redirect_uri=redirect%3A%2F%2Fme&client_id=" + TEST_CLIENT_ID + "&response_type=code&scope=*"+
380+
"&display=popup&state=stateValue")
381+
);
382+
}
383+
364384
@Test
365385
public void shouldCallTokenStateListenerWhenTokenIsInvalidated() throws Exception {
366386
CloudAPI.TokenListener listener = mock(CloudAPI.TokenListener.class);

0 commit comments

Comments
 (0)