Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Schout

macrumors newbie
Original poster
Aug 9, 2020
8
0
Greetings,

I'm trying to put together an app for a scheduling program at work.

Presently, everything is web based and requires a user ID and login to access your own personal schedule.

I would like to build a basic app that will automatically refresh and fetch the most current schedule (think how an airline app might work with your reservation) so it is available offline.

The company contracts with a third party to develop their web based scheduling, so I won't have direct access to their code or databases. In other words, it will need to be able to download my schedule using my existing user level credentials.

In a nutshell, the work flow is something like this - log in using current credentials for the web based scheduling, have the app display and download any existing schedule, keep the latest schedule available offline. Refresh automatically in the background when internet is available and push a notification of any changes from the previous schedule.

Is this possible? What tools would I need to execute such a project? For now, I have Xcode and am getting familiar with Swift. I'm assuming I'll need some type of database to store the data. The biggest question I have is being able to do this only with user level credentials. I assume this is possible though (think of an email client where you feed it your credentials for Gmail, etc).

Thanks in advance!

Schout
 

casperes1996

macrumors 604
Jan 26, 2014
7,517
5,685
Horsens, Denmark
Well, the difference with email is that it's standardised.
A recommendation here is to use a network packet capture tool to capture yourself logging into your work thing. Then look at the packets that were sent and received; Send the same datagram from within your swift code and see if you get a similar packet back, then try and parse it as a string; It will likely just be HTML+CSS+JS, and see if you can parse out the schedule info from that
 

casperes1996

macrumors 604
Jan 26, 2014
7,517
5,685
Horsens, Denmark
Oh and as for databasing; Depending on how much data you plan to write and keep; iOS comes with CoreData which is SQLite backed, or you can just use the UserDefaults system which is KV(Key-Value· Like a dictionary/Map) based storage
 

Schout

macrumors newbie
Original poster
Aug 9, 2020
8
0
I really appreciate the quick response, and you obviously know what you are doing...

I fear that it will take me some time to figure out how exactly to accomplish the network packet capture, but I'm sure that I will get there. It sounds like a good first step though.

Once I figure out and capture the packet, how would I go about sending the datagram from Swift and receiving something back? Did I mention I'm a newbie? ??
 

casperes1996

macrumors 604
Jan 26, 2014
7,517
5,685
Horsens, Denmark
I really appreciate the quick response, and you obviously know what you are doing...

I fear that it will take me some time to figure out how exactly to accomplish the network packet capture, but I'm sure that I will get there. It sounds like a good first step though.

Once I figure out and capture the packet, how would I go about sending the datagram from Swift and receiving something back? Did I mention I'm a newbie? ??

Right; Working with services that aren't documented with APIs and that you aren't in control of can be hard for everyone, and you'd also constantly be at the risk that if they change anything about how data is received or sent, your app will stop working until you react to it. I once did (for fun) a little weather thingy that just sent a GET request to a weather website, parsed the HTML and presented the 7-day forecast text. But they changed the formatting on the site and the whole thing broke.

In any case, for capturing you can use Wireshark; There may be other options, but Wireshark is a well known packet capture tool. Though data can be hard to parse with it and may take a lot of time to figure out what's what and such once you've captured traffic.

As for sending the data to the site; A TCP socket is one way but that's code-wise rather low level, though it gives full control over sending and receiving.
Apple has an API called something like URLSession which would do a lot of work for you, especially with respect to handling SSL encryption which I would assume your corporate site thingy to use since it handles login information. On the flip side however, I don't know how that API works when you want to send more than a GET request - I haven't used that sort of networking much.
But you can likely find information on how to use it by looking it up in Apple's developer documentation

Here's Apple's own information on it
 

Handoff

macrumors newbie
Dec 3, 2019
29
21
hmm if it's a web app then it should be pretty easy to get the data.

Just make a POST request with the username and password, make another POST\GET request to get the schedule and save the response.

You can easily do something like that straight from the terminal to test it:

Login to the app and save the cookies to a file to be used for later
curl --cookie-jar cookies.txt --form un=test --form pw=testpw http://example.com/login

un is the username field (inspect the page to see what's the real field's name)
pw is the password field (inspect the page to see what's the real field's name)

Fetch the data:
curl --cookie-jar cookies.txt http://example.com/schedule


To do it in Swift, use NSURLSession. Make sure you set a "normal" user agent just in case.
 
  • Like
Reactions: casperes1996

Schout

macrumors newbie
Original poster
Aug 9, 2020
8
0
Here is a screen shot of the login page, as well as the form data presented after login. I'll pay around with all suggestions. Most of this is still way over my head unfortunately. I'm studying a bit every day though.

- Schout

B82D0FFD-1D11-4C6A-AB64-434D7EA20917.jpeg
 

Attachments

  • 9B1951DF-33B2-4149-A629-580BF53E6533.jpeg
    9B1951DF-33B2-4149-A629-580BF53E6533.jpeg
    321.9 KB · Views: 119

Schout

macrumors newbie
Original poster
Aug 9, 2020
8
0
Okay, so it looks like I was able to login through the terminal using:

curl --user myusername normalwebsiteaddress

It returns "Enter host password for user 'myusername':

I enter my password and it displays:


<html>

<head>

<meta HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">

<META

http-equiv="refresh"content="0;URL=normalwebsiteaddress/testweb>


<title ID=titletext>Redirecting to Example Website's Portal</title>


</head>


<body bgcolor=white>Loading Website Portal


</body>

</html>

I'm getting stuck on how to save the cookies and use that in the terminal to access the page with the schedule as it appears to redirect. How do I go about doing this POST/GET response?

Thanks guys!!!
 
Last edited:

Schout

macrumors newbie
Original poster
Aug 9, 2020
8
0
Still having issues logging in with cURL

If I use curl --user myusername: (space intention here so it doesn't insert and emoji) password https://example.mywebsite.com it appears to login. However, when I extract the entire URL https://example.mywebsite.com/testweb/Authentication/Logon?ReturnUrl=%2ftestweb%2f and try the same process it kicks back the page that says I've entered the wrong username and password. It works in a browser though...
 

casperes1996

macrumors 604
Jan 26, 2014
7,517
5,685
Horsens, Denmark
Here is a screen shot of the login page, as well as the form data presented after login. I'll pay around with all suggestions. Most of this is still way over my head unfortunately. I'm studying a bit every day though.

- Schout

View attachment 943178

If this was in reaction to what was written about "inspecting" the name of the fields -

Enable Developer mode on your browser - I use Safari, so that's a toggle in the Safari Preferences. Then you can right click elements on a web-page and click "Inspect element". That will show you the corresponding HTML
 

Schout

macrumors newbie
Original poster
Aug 9, 2020
8
0
If I use curl --user myusername: (space intention here so it doesn't insert and emoji) password https://example.mywebsite.com it appears to login. However, when I extract the entire URL https://example.mywebsite.com/testweb/Authentication/Logon?ReturnUrl=%2ftestweb%2f and try the same process it kicks back the page that says I've entered the wrong username and password. It works in a browser though...
[/QUOTE]
Screen Shot 2020-08-11 at 12.23.55.png
Screen Shot 2020-08-11 at 12.23.48.png
 

casperes1996

macrumors 604
Jan 26, 2014
7,517
5,685
Horsens, Denmark
Bump...ideas?

Bit hard when we don't have the site and credentials to try out things, and also I'm not entirely sure I understood your problem. But this might help:


https://example.mywebsite.com/testweb/Authentication/Logon?ReturnUrl=%2ftestweb%2f

In the URL encoding scheme, the bit after the question mark: "?ReturnURL[...]" is a variable being sent to the web server and not strictly speaking part of the resource locator (as in Universal Resource Locator, URL). And %2f is /. So it's saying that on the page
/Authentication/Logon, the web server should be told that the ReturnUrl variable should be set to /testweb/
 

Schout

macrumors newbie
Original poster
Aug 9, 2020
8
0
I'm very much new to this so I am probably having a hard time defining my problem(s). We have web based scheduling which requires individual credentials to log-in. Once logged in, it is possible to view your past or upcoming schedule (in various levels of detail). We spend a lot of time out of any kind of internet signal (like traveling on airplanes) but it would be super helpful to have access to the most recent data via an app.

I'd like the app to pull the data from our web based schedule and save it for viewing inside of the app. I think I can figure out the display part, but I'm really confused on how to send the credentials (log in) and then how to download the data and store it locally.

My vision would be like how an airline application works where your boarding pass and gate information are stored even when you are offline, and then refresh that data once connected again.

Thanks again
 

Handoff

macrumors newbie
Dec 3, 2019
29
21
The problem is knowing to which URL the login info is being POSTed. You can PM the login URL if you want and I can check it.


Make sure you're running the curl command in a directory you have permissions to create a file. But keep in mind that curl is just a quick way to fetch the data, you might want to do the login + data fetch inside an app. CHeck this very good stackoverflow answer on the subject: https://stackoverflow.com/a/38135834/462047
 

casperes1996

macrumors 604
Jan 26, 2014
7,517
5,685
Horsens, Denmark
I'm very much new to this so I am probably having a hard time defining my problem(s). We have web based scheduling which requires individual credentials to log-in. Once logged in, it is possible to view your past or upcoming schedule (in various levels of detail). We spend a lot of time out of any kind of internet signal (like traveling on airplanes) but it would be super helpful to have access to the most recent data via an app.

I'd like the app to pull the data from our web based schedule and save it for viewing inside of the app. I think I can figure out the display part, but I'm really confused on how to send the credentials (log in) and then how to download the data and store it locally.

My vision would be like how an airline application works where your boarding pass and gate information are stored even when you are offline, and then refresh that data once connected again.

Thanks again

Hehe, sorry; I got all that. When I said I was unsure about your problem, I meant because you said something about the login through curl working on the base URL, so I didn't get the further problem from that.
Unless there's like an incredibly severe legal risk or something I recommend taking Handoff's offer on PM'ing him the actual URL so he can experiment for you. He knows his stuff.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.