Advertisement
Guest User

login script cas

a guest
Oct 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.16 KB | None | 0 0
  1. final response = await HttpRequest.get(loginUrl);
  2.  
  3.     if (!response.isSuccess) return LoginResult(LoginResultType.NETWORK_ERROR);
  4.  
  5.     final document = parse(response.httpResponse.body);
  6.  
  7.     // Extract lt value from HTML
  8.     final ltInput = document.querySelector('input[name="lt"]');
  9.     String lt = "";
  10.     if (ltInput?.attributes?.containsKey("value") ?? false)
  11.       lt = ltInput.attributes['value'];
  12.  
  13.     final executionInput = document.querySelector('input[name="execution"]');
  14.     String execution = "e1s1";
  15.     if (executionInput?.attributes?.containsKey("value") ?? false)
  16.       execution = executionInput.attributes['value'];
  17.  
  18.     // POST data
  19.     Map<String, String> postParams = {
  20.       "_eventId": "submit",
  21.       "lt": lt,
  22.       "submit": "LOGIN",
  23.       "username": username,
  24.       "password": password,
  25.       "execution": execution,
  26.     };
  27.  
  28.     // Get JSESSIONID from previous request header
  29.     final cookie = response.httpResponse.headers["set-cookie"];
  30.  
  31.     // Second request, with all necessary data
  32.     final loginResponse = await HttpRequest.post(
  33.       loginUrl,
  34.       body: postParams,
  35.       headers: {"cookie": cookie},
  36.     );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement