simplyGits / magisterjs-authcode

1 stars 1 forks source link

Auth token expiry #3

Open EttoreRaimondi opened 5 years ago

EttoreRaimondi commented 5 years ago

Hey guys, cant seems to find the answer anywhere. Could you please tell me how long this token stays active for? How long before it expires?

jvdoorn commented 5 years ago

If I remember correctly.. we don't know either. This token is provided by Magister if you were to log in using a browser, it changes every now and then.

The fact that you don't know when it changes, and thus not knowing when to update the token is a bit annoying. There are three things you can do:

  1. Before running your code, update packages (npm up). That should fetch the latest version of the package and update your token.

  2. Use magisterjs-dynamic-authcode, this will allow you to fetch the latest version of the authcode and provide it to MagisterJS.

  3. Query the code yourself using an HTTP-GET request (see the README.md).

The first option is probably the only convenient if you are running MagisterJS from a script (you could then just run npm up before node your-script-using-magister.js). The second and third option are probably best to use when you distribute the code and don't want end users to have the hastle of having to run npm up before using your code (and when you package it using electron par example this is probably not possible even).

EttoreRaimondi commented 5 years ago

Thanks so much for the reply.

Currently I'm querying the url for the Auth code. works well :) was just curious as to expiry time.

We are working on an old laravel 4, php 5.6 project that makes use of magister. The only difficulty in debugging issues is that there is no real documentation for anything that was done. The project has taken the web scraping approach and therefore makes it even more difficult. We would like to use a REST API where possible but cant seem to find any documentation. Any tips here?

jvdoorn commented 5 years ago

You could take a look at how MagisterJS handles things, it might be easier to port the Javascript code to PHP/Laravel than to update the existing code. The reason for this is that Magister changed quite some stuff so that code possibly doesn't even work at all and secondly, MagisterJS makes use of the Magister's API (which Magister uses to fetch your appointments, grades, etc.) which is probably a better approach then scraping the data.

If you go to your school's Magister and look at the network tab in your inspector (that's on Firefox at least, not sure what it's called on Chrome or other browsers) you can see the requests Magister makes to the API.

You could also let the PHP/Laravel stuff maybe use MagisterJS? I don't really know PHP so I'm not sure if you could call node scripts from it.