use publicUrl setting for rendering callback url

This commit is contained in:
Athou
2013-04-16 10:12:37 +02:00
parent 6c544237b2
commit 2067bceff4
3 changed files with 11 additions and 11 deletions

View File

@@ -57,7 +57,8 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
mountPage("error", DisplayExceptionPage.class); mountPage("error", DisplayExceptionPage.class);
mountPage("favicon", FaviconPage.class); mountPage("favicon", FaviconPage.class);
mountPage("google/import/redirect", GoogleImportRedirectPage.class); mountPage("google/import/redirect", GoogleImportRedirectPage.class);
mountPage("google/import/callback", GoogleImportCallbackPage.class); mountPage(GoogleImportCallbackPage.PAGE_PATH,
GoogleImportCallbackPage.class);
mountPage("testfeed", TestRssPage.class); mountPage("testfeed", TestRssPage.class);

View File

@@ -5,9 +5,6 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.wicket.RestartResponseException; import org.apache.wicket.RestartResponseException;
import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.request.Url;
import org.apache.wicket.request.UrlRenderer;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.commafeed.backend.dao.UserDAO; import com.commafeed.backend.dao.UserDAO;
@@ -33,6 +30,8 @@ public class GoogleImportCallbackPage extends WebPage {
private static final String TOKEN_URL = "https://accounts.google.com/o/oauth2/token"; private static final String TOKEN_URL = "https://accounts.google.com/o/oauth2/token";
private static final String EXPORT_URL = "https://www.google.com/reader/subscriptions/export"; private static final String EXPORT_URL = "https://www.google.com/reader/subscriptions/export";
public static final String PAGE_PATH = "google/import/callback";
@Inject @Inject
ApplicationSettingsService applicationSettingsService; ApplicationSettingsService applicationSettingsService;
@@ -42,11 +41,11 @@ public class GoogleImportCallbackPage extends WebPage {
@Inject @Inject
UserDAO userDAO; UserDAO userDAO;
public static String getCallbackUrl() { public static String getCallbackUrl(String publicUrl) {
RequestCycle cycle = RequestCycle.get(); if (publicUrl.endsWith("/")) {
UrlRenderer renderer = cycle.getUrlRenderer(); publicUrl = publicUrl.substring(0, publicUrl.length() - 1);
return renderer.renderFullUrl(Url.parse(cycle.urlFor( }
GoogleImportCallbackPage.class, null).toString())); return publicUrl + "/" + PAGE_PATH;
} }
public GoogleImportCallbackPage(PageParameters params) { public GoogleImportCallbackPage(PageParameters params) {
@@ -67,7 +66,7 @@ public class GoogleImportCallbackPage extends WebPage {
throw new DisplayException("Missing authorization code"); throw new DisplayException("Missing authorization code");
} else { } else {
ApplicationSettings settings = applicationSettingsService.get(); ApplicationSettings settings = applicationSettingsService.get();
String redirectUri = getCallbackUrl(); String redirectUri = getCallbackUrl(settings.getPublicUrl());
String clientId = settings.getGoogleClientId(); String clientId = settings.getGoogleClientId();
String clientSecret = settings.getGoogleClientSecret(); String clientSecret = settings.getGoogleClientSecret();

View File

@@ -30,7 +30,7 @@ public class GoogleImportRedirectPage extends WebPage {
String clientId = settings.getGoogleClientId(); String clientId = settings.getGoogleClientId();
String redirectUri = GoogleImportCallbackPage.getCallbackUrl(); String redirectUri = GoogleImportCallbackPage.getCallbackUrl(settings.getPublicUrl());
try { try {
URIBuilder builder = new URIBuilder(AUTH_URL); URIBuilder builder = new URIBuilder(AUTH_URL);