Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#239 PsLinkedin passes the request parameters to the URI. #245

Merged
merged 5 commits into from
May 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/main/java/org/takes/facets/auth/social/PsLinkedin.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,17 @@ private Identity fetch(final String token) throws IOException {
*/
private String token(final String home, final String code)
throws IOException {
final String uri = this.tkhref
.with("grant_type", "authorization_code")
.with("client_id", this.app)
.with("client_secret", this.key)
.with("redirect_uri", home)
.with("code", code)
.toString();
final String uri = this.tkhref.toString();
return new JdkRequest(uri)
.method("POST")
.header("Accept", "application/xml")
.body()
.formParam("grant_type", "authorization_code")
.formParam("client_id", this.app)
.formParam("redirect_uri", home)
.formParam("client_secret", this.key)
.formParam("code", code)
.back()
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.as(JsonResponse.class)
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/takes/facets/auth/social/PsLinkedinTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import javax.json.Json;
import org.apache.commons.lang.RandomStringUtils;
import org.hamcrest.CoreMatchers;
Expand All @@ -41,6 +42,8 @@
import org.takes.http.FtRemote;
import org.takes.misc.Href;
import org.takes.rq.RqFake;
import org.takes.rq.RqHref;
import org.takes.rq.RqPrint;
import org.takes.rs.RsJSON;

/**
Expand All @@ -67,9 +70,29 @@ public void logins() throws IOException {
final Take take = new TkFork(
new FkRegex(
"/uas/oauth2/accessToken",
// @checkstyle AnonInnerLengthCheck (100 lines)
new Take() {
@Override
public Response act(final Request req) throws IOException {
MatcherAssert.assertThat(
new RqPrint(req).printBody(),
Matchers.stringContainsInOrder(
Arrays.asList(
"grant_type=authorization_code",
String.format("client_id=%s", lapp),
"redirect_uri=",
String.format(
"client_secret=%s",
lkey
),
String.format("code=%s", code)
)
)
);
MatcherAssert.assertThat(
new RqHref.Base(req).href().toString(),
Matchers.endsWith("/uas/oauth2/accessToken")
);
return new RsJSON(
Json.createObjectBuilder()
.add(
Expand Down