Skip to content
Browse files

Allowing redirectUri to be overridden to support a single callback ur…

…l to be set for both connect and signin callbacks, as SoundCloud only supports a single exact match callback url
  • Loading branch information...
1 parent d784345 commit 5db94da9ff4ce2445d513538818e79348526718f @michaellavelle committed Jan 7, 2012
View
6 src/main/java/org/springframework/social/soundcloud/connect/SoundCloudConnectionFactory.java
@@ -10,7 +10,11 @@
public class SoundCloudConnectionFactory extends OAuth2ConnectionFactory<SoundCloud> {
public SoundCloudConnectionFactory(String clientId, String clientSecret) {
- super("soundcloud", new SoundCloudServiceProvider(clientId, clientSecret), new SoundCloudAdapter());
+ this(clientId,clientSecret,null);
+ }
+
+ public SoundCloudConnectionFactory(String clientId, String clientSecret,String redirectUri) {
+ super("soundcloud", new SoundCloudServiceProvider(clientId, clientSecret,redirectUri), new SoundCloudAdapter());
}
}
View
48 src/main/java/org/springframework/social/soundcloud/connect/SoundCloudOAuth2Template.java
@@ -3,16 +3,26 @@
import java.util.Map;
import org.springframework.social.oauth2.AccessGrant;
+import org.springframework.social.oauth2.GrantType;
+import org.springframework.social.oauth2.OAuth2Parameters;
import org.springframework.social.oauth2.OAuth2Template;
+import org.springframework.util.MultiValueMap;
/**
* SoundCloud-specific extension of OAuth2Template
* @author Michael Lavelle
*/
public class SoundCloudOAuth2Template extends OAuth2Template {
- public SoundCloudOAuth2Template(String clientId, String clientSecret) {
+ private String redirectUri;
+
+ public SoundCloudOAuth2Template(String clientId, String clientSecret,String redirectUri) {
super(clientId, clientSecret, "https://soundcloud.com/connect", "https://api.soundcloud.com/oauth2/token");
+ this.redirectUri = redirectUri;
+ }
+
+ public SoundCloudOAuth2Template(String clientId, String clientSecret) {
+ this(clientId, clientSecret,null);
}
@Override
@@ -22,6 +32,42 @@ protected AccessGrant createAccessGrant(String accessToken, String scope,
response);
}
+ @Override
+ public String buildAuthenticateUrl(GrantType grantType,
+ OAuth2Parameters parameters) {
+ if (redirectUri != null)
+ {
+ parameters.setRedirectUri(redirectUri);
+ }
+ return super.buildAuthenticateUrl(grantType, parameters);
+ }
+
+ @Override
+ public String buildAuthorizeUrl(GrantType grantType,
+ OAuth2Parameters parameters) {
+ if (redirectUri != null)
+ {
+ parameters.setRedirectUri(redirectUri);
+ }
+ return super.buildAuthorizeUrl(grantType, parameters);
+ }
+
+ @Override
+ public AccessGrant exchangeForAccess(String authorizationCode,
+ String redirectUri,
+ MultiValueMap<String, String> additionalParameters) {
+ return super.exchangeForAccess(authorizationCode, this.redirectUri != null ? this.redirectUri : redirectUri,
+ additionalParameters);
+ }
+
+
+
+
+
+
+
+
+
View
7 src/main/java/org/springframework/social/soundcloud/connect/SoundCloudServiceProvider.java
@@ -13,7 +13,12 @@
private String clientId;
public SoundCloudServiceProvider(String clientId, String clientSecret) {
- super(new SoundCloudOAuth2Template(clientId, clientSecret));
+ this(clientId,clientSecret,null);
+ }
+
+
+ public SoundCloudServiceProvider(String clientId, String clientSecret,String redirectUri) {
+ super(new SoundCloudOAuth2Template(clientId, clientSecret,redirectUri));
}
@Override

0 comments on commit 5db94da

Please sign in to comment.
Something went wrong with that request. Please try again.