edu-sync icon indicating copy to clipboard operation
edu-sync copied to clipboard

support OAuth2 login

Open jonassmedegaard opened this issue 1 year ago • 9 comments

I study at a univsersity that uses OAuth2 for login to Moodle, and would be delighted if possible to use this nice looking tool.

I am a Debian developer, and am prepared to maintain packaging of this project officially for Debian, but am currently holding back due to not being able to use it myself.

Please consider adding OAuth2 support.

jonassmedegaard avatar Sep 29 '24 02:09 jonassmedegaard

Does your instance not provide a token in preferences -> security keys?

I am open to adding OAuth2 support, but I currently don't have the time to look into it myself.

mkroening avatar Oct 23 '24 10:10 mkroening

It is not "my" moodle, but the one at my university, that I want to interact with: https://moodle.ruc.dk/

They use Microsoft as authentication broker, which as I understand it means that they comply with OAuth2.

Sorry if I am mistaken or rambling here, I am a mere beginner in fumbling with Moodle, and only as a user.

jonassmedegaard avatar Oct 23 '24 10:10 jonassmedegaard

Having a full OAuth2 flow in a CLI application is probably difficult. All edu-sync needs is a token for accessing moodle.

For my university's moodle (https://moodle.rwth-aachen.de/) I perform the following steps for setting up edu-sync:

  1. Log into a moodle app (on Android or iOS), since that sets up a token.
  2. Log into the moodle web page and go to preferences → security keys.
  3. Look for “Moodle mobile web service” and use that token with edu-sync.

There might be better solutions to acquiring a token and some moodle instances don't show security keys on the website. An OAuth2 flow for edu-sync would be cool too, but not very easy, I would estimate.

mkroening avatar Oct 23 '24 11:10 mkroening

Thanks.

Unfortunately it seems "my" moodle do not provide an entry in preferences called "security keys". I have logged in from dawdle and in (not preferences but) profile I have the option to establish a new mobile session using a QR code or to terminate the mobile session I already have established - but no access to get the token, it seems :-(

jonassmedegaard avatar Oct 23 '24 12:10 jonassmedegaard

I am also interested in this. My university's Moodle uses Shibboleth for login. I am able to login on the Moodle Android app but the only token listed in the Settings is for RSS. I have tried looking into extracting the token some other way but so far to no avail.

abtsousa avatar Oct 26 '24 15:10 abtsousa

Hey, I had the same issue, the moodle server is behind SSO (no dedicated username/password) and has no Security keys section. I just wanting to share how I managed to find a workaround. I actually used a similar project Moodle-DL that has a setup flow where it opens a URL to get the token, I reused this token with edu-sync-cli and it worked.

Here are the quick steps to try this

pip install moodle-dl
moodle-dl --init --sso # follow the steps
cat config.json

Here is the output you should expect (all domains and token have been replaced with <...> obviously)

> moodle-dl --init --sso
Do you want to activate Notifications via Discord? (y/N) 
Do you want to activate Notifications via mail? (y/N) 
Do you want to activate Notifications via Telegram? (y/N) 
Do you want to activate Notifications via XMPP? (y/N) 
Do you want to configure Error Reporting via Sentry? (y/N) 
URL of Moodle:   https://<moodle server domain>
Please use the Chrome browser for the following procedure
1. Log into your Moodle Account
2. Open the developer console (press F12) and go to the Network tab
3. Then visit the following URL in the same browser tab you have logged in:
https://<moodle server domain>/admin/tool/mobile/launch.php?service=moodle_mobile_app&passport=12345&urlscheme=moodledl

If you open the link, no web page should load, instead an error will occur. In the Network tab of the developer console you opened before there should be an error entry.
The script expects a URL that looks something like this:
moodledl://token=$apptoken
 Where $apptoken looks random and "moodledl" can also be a different url scheme  like "moodlemobile". In reality $apptoken is a Base64 string containing the token to access moodle.
4. Copy the link address of the website that could not be loaded (right click the list entry, then click on Copy, then click on copy link address)
Then insert the link address here:   moodledl://token=<long base64 value here>

Token successfully saved!

> cat config.json 
{
    "token": "<your token should be here>",
    "moodle_domain": "<moodle server domain>",
    "moodle_path": "/"
}

Note: for step 4, you can always look at the HTTP response header Location where you see the redirection to moodledl://token=... if this step is not clear.

Now you have the token, you can copy paste it during the edu-sync setup and delete the config.json from Moodle-DL.

@abtsousa and @jonassmedegaard, let me know if it solves your issue !

samuelroland avatar Oct 30 '24 10:10 samuelroland

@samuelroland your solution worked perfectly. Just to add, the moodle-dl script loads the correct url, and the token in the moodledl:/// URL is just a long string in base64 made of a few strings joined by ::: where the second string is the token you want. I just finished setting up moodle-DL and it took care of everything automatically and I just had to extract the token from config.json. Thanks :)

abtsousa avatar Oct 30 '24 16:10 abtsousa

Unfortunately it seems "my" moodle do not provide an entry in preferences called "security keys".

What might add to the confusion, my Moodle instance has a section titled Security Keys which does show a token, but this token only seems to be valid for RSS feeds and consequently wasn't accepted. Meanwhile, extracting the mobile app token from the HTTP response header worked flawlessly.

Maybe this could be mentioned in the README?

gwuen avatar Feb 12 '25 12:02 gwuen

Maybe this could be mentioned in the README?

Feel free to open a PR. :)

mkroening avatar Feb 14 '25 13:02 mkroening