Skip to content

Commit

Permalink
[F] Fix SJP login
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna committed Mar 10, 2022
1 parent f3ed7ff commit 5d885ce
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/main/java/org/hydev/veracross/sdk/StJohnsHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ public class StJohnsHttpClient extends GeneralHttpClient

private String username;

/**
* Get the session's authenticity token
*
* @return CSRF token
*/
public String getCsrf() throws IOException
{
// Exmaple response: <input name="authenticity_token" type="hidden" value="oLeYfaLYmQDScdhx9fR5jpgvyjBXDCC36NTvfIjkBkgrsyCxA+KO71Du9n1MvJqNbjRK1R+HCl4OlmGlrpqRSg==">
String response = getBody("https://www.stjohnsprep.org/fs/sessions/user/csrf-token");

// Example CSRF Token: oLeYfaLYmQDScdhx9fR5jpgvyjBXDCC36NTvfIjkBkgrsyCxA+KO71Du9n1MvJqNbjRK1R+HCl4OlmGlrpqRSg==
return response.substring(response.indexOf("value=\"") + 7, response.indexOf("\">"));
}

/**
* Login and save the session
*/
Expand All @@ -42,10 +56,11 @@ public void login(String username, String password) throws IOException, Veracros
this.username = username;

// Post request
CloseableHttpResponse response = postForm("https://www.stjohnsprep.org/userlogin.cfm?do=login&p=114", null,
"username", username,
"password", password,
"submit", "login");
CloseableHttpResponse response = postForm("https://www.stjohnsprep.org/fs/auth/finalsite/callback", null,
"username", username,
"password", password,
"protected_page", "false",
"authenticity_token", getCsrf());

// Get response
int status = response.getStatusLine().getStatusCode();
Expand Down

0 comments on commit 5d885ce

Please sign in to comment.