Skip to content

Commit

Permalink
First prototype of request continuation instead of redirection after …
Browse files Browse the repository at this point in the history
…OAuth2Callback.
  • Loading branch information
t-burch committed Nov 8, 2024
1 parent ce7e28a commit b158620
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import com.predic8.membrane.core.interceptor.oauth2client.*;
import com.predic8.membrane.core.interceptor.oauth2client.rf.token.*;
import com.predic8.membrane.core.interceptor.session.*;
import com.predic8.membrane.core.transport.http.HttpClient;
import com.predic8.membrane.core.util.*;
import org.apache.http.impl.client.DefaultHttpClient;
import org.slf4j.*;

import java.math.*;
Expand Down Expand Up @@ -196,9 +198,15 @@ private Map<String, Object> exchangeCodeForToken(String tokenEndpoint, String pu
});
}

private static void doRedirect(Exchange exc, AbstractExchangeSnapshot originalRequest, Session session) throws JsonProcessingException {
private static void doRedirect(Exchange exc, AbstractExchangeSnapshot originalRequest, Session session) throws Exception {
if (originalRequest.getRequest().getMethod().equals("GET")) {
exc.setResponse(Response.redirect(originalRequest.getOriginalRequestUri(), false).build());
HttpClient hc = new HttpClient();
Exchange ogExc = (Exchange) originalRequest.toAbstractExchange();
System.out.println(ogExc.getDestinations());
hc.call(ogExc);
exc.setResponse(ogExc.getResponse());

//exc.setResponse(Response.redirect(originalRequest.getOriginalRequestUri(), false).build());
} else {
String oa2redirect = new BigInteger(130, new SecureRandom()).toString(32);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,8 @@ static void step9exchangeCodeForToken(String location) {
.when()
.post(location)
.then()
.statusCode(307)
.header(LOCATION, "/a?b=c&d=%20")
.statusCode(200)
.extract().response();
}

static void step10makeAuthPostRequest() {
given()
.cookies(memCookies)
.when()
.post(CLIENT_URL)
.then()
.body(equalToIgnoringCase("get"));
}
// @formatter:on
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,9 @@ void testGet() {
// Step 8: Redirect back to client
String callbackUrl = step8redirectToClient();

// Step 9: Exchange Code for Token
// Step 9: Exchange Code for Token & continue original request.·
step9exchangeCodeForToken(callbackUrl);

// Step 10: Make the authenticated POST request
step10makeAuthPostRequest();


assertEquals(firstUrlHit.get(), targetUrlHit.get(), "Check that URL survived encoding.");
}

Expand Down

0 comments on commit b158620

Please sign in to comment.