Integration of Moodle and oCIS
A Moodle repository that makes files stored in oCIS accessible through the Moodle file-picker.
- oCIS PHP SDK
- moodle 4.2
- PHP 8.1
- oCIS 5.0
The existing OAuth2 implementation in Moodle does support OpenID connect, so a custom Oauth2 service is used to connect to oCIS.
2. Link files between Moodle & oCIS using the Moodle file-picker
There are three different modes for the Moodle user to link files from oCIS to Moodle:
-
Internal (Make a copy of the file)
In this case the file is copied from oCIS and stored within the Moodle file system.
-
Reference: (Link to the file) 🚧 This feature is not implemented yet 👩💻
In this case a public link of the file is created in oCIS and Moodle stores this link
-
Controlled Link: (Create an access controlled link to the file) 🚧 This feature is not implemented yet 👨💻
For this to work a special oCIS account needs to be connected to Moodle that will be used as a System account. If the user selects the "Controlled Link" option, the file will be shared to the System account and Moodle will access it through the System account.
- TLS certificate
The TLS certificates of oCIS need to be trusted by the server running moodle. If your oCIS instance has already a trusted certificate you can skip this step.
If you are using self-signed certificates you need to copy them to the moodle server and make it trust them. e.g. on Debian based systems to run oCIS on
https://host.docker.internal:9200
:- create a TLS certificate
openssl req -x509 -newkey rsa:2048 -keyout ocis.pem -out ocis.crt -nodes -days 365 -subj '/CN=host.docker.internal'
- make 'host.docker.internal' resolve to the IP 127.0.0.1 on the docker host machine
sudo sh -c "echo '127.0.0.1 host.docker.internal' >> /etc/hosts"
- create a TLS certificate
- Install moodle and this plugin
- Development environment with docker:
moodle will now be available under http://localhost:8000
# get moodle from git git clone https://github.com/moodle/moodle.git --branch MOODLE_402_STABLE --single-branch --depth=1 # get and install this plugin including it's dependencies cd moodle/repository/ git clone https://github.com/owncloud/moodle-repository_ocis.git ocis # get docker containers for moodle developers cd ../../ git clone https://github.com/moodlehq/moodle-docker.git cd moodle-docker # some general settings for moodle export MOODLE_DOCKER_WWWROOT=<path-of-your-moodle-source-code> export MOODLE_DOCKER_DB=pgsql export MOODLE_DOCKER_PHP_VERSION=8.1 cp config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php # disable some security settings, that would block access to non standard ports and local addresses # !DON'T DO THAT FOR PRODUCTION INSTALLATIONS! sed -i "s|require_once(__DIR__ . '/lib/setup.php');|\$CFG->curlsecurityblockedhosts = '';\n\$CFG->curlsecurityallowedport = '';\n\$CFG->behat_extraallowedsettings = ['curlsecurityblockedhosts', 'curlsecurityallowedport'];\nrequire_once(__DIR__ . '/lib/setup.php');|" $MOODLE_DOCKER_WWWROOT/config.php # allow container to access docker host via 'host.docker.internal' cat > local.yml <<'EOF' services: webserver: extra_hosts: - host.docker.internal:host-gateway environment: MOODLE_OCIS_URL: "https://host.docker.internal:9200" # optional, used to create OAuth 2 services and repository instance during installation MOODLE_OCIS_CLIENT_ID: "xdXOt13JKxym1B1QcEncf2XDkLAexMBFwiT9j6EfhhHFJhs2KM9jbjTmf8JBXE69" # optional, used to create OAuth 2 services and repository instance during installation MOODLE_OCIS_CLIENT_SECRET: "UBntmLjC2yYCeHwsyj73Uwo9TAaecAetRwMw0xYcvNL9yRdLSUi0hUAHfvCHFeFh" # optional, used to create OAuth 2 services and repository instance during installation EOF # run moodle bin/moodle-docker-compose up -d # if oCIS will run with a self signed certificate copy that into the moodle container and make it trust it bin/moodle-docker-compose cp </path/of/ocis.crt> webserver:/usr/local/share/ca-certificates/ bin/moodle-docker-compose exec webserver update-ca-certificates bin/moodle-docker-wait-for-db bin/moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="Docker moodle" --shortname="docker_moodle" --summary="Docker moodle site" --adminpass="admin" --adminemail="[email protected]"
- Other installation methods (require to install and run moodle first):
- Install the plugin using git:
- Clone the code of this repository into the
repository/ocis
folder of your moodle installation:git clone https://github.com/owncloud/moodle-repository_ocis.git <moodle-path>/repository/ocis
- Checkout the wanted version:
cd <moodle-path>/repository/ocis git checkout v<the-required-version-of-the-plugin>
- Clone the code of this repository into the
- Install the plugin using a downloaded ZIP file:
- Download the ZIP file of the last release from GitHub
- In your moodle installation login as administrator
- Navigate to the "Plugin installer" (Site administration -> Plugins -> Install plugins)
- Upload the ZIP package of the plugin
- Click the
Install plugin from the ZIP file
button
- Install the plugin using git:
- Development environment with docker:
- Install & run oCIS
If you have created an own TLS certificate in point 1, run oCIS using this certificate:
❗ Having set
OCIS_INSECURE=true \ PROXY_HTTP_ADDR=0.0.0.0:9200 \ OCIS_URL=https://host.docker.internal:9200 \ PROXY_TRANSPORT_TLS_KEY=</path/of/ocis.pem> \ PROXY_TRANSPORT_TLS_CERT=</path/of/ocis.crt> \ ./ocis server
OCIS_INSECURE=true
is not recommended for production use! ❗ - Login to moodle as "admin"
- If you run oCIS on
localhost
or any local IP address go to the "HTTP security" page ("Site administration" > "General" > "Security" > "HTTP security") and delete the IP address and host-name you are using from the "cURL blocked hosts list" list. E.g if you have been following the examples above and usinghttps://host.docker.internal:9200
as the address for oCIS, you will have to delete172.16.0.0/12
from the list. - If you run oCIS on any port other than
443
go to the "HTTP security" page ("Site administration" > "General" > "Security" > "HTTP security") and add the port you are using to the "cURL allowed ports list" list. E.g. if you have been following the examples above add9200
to the list. - Go to the "OAuth 2 services" page ("Site administration" > "Server" >"Server" > "OAuth 2 services")
- Create a new "Custom" service
- Choose any name you like
- Set "Client ID".
If moodle runs on
localhost
the IDxdXOt13JKxym1B1QcEncf2XDkLAexMBFwiT9j6EfhhHFJhs2KM9jbjTmf8JBXE69
can be used for testing, else another client need to be set up in the oCIS IDP - Set "Client secret"
If moodle runs on
localhost
the secretUBntmLjC2yYCeHwsyj73Uwo9TAaecAetRwMw0xYcvNL9yRdLSUi0hUAHfvCHFeFh
can be used for testing, else another client need to be set up in the oCIS IDP - Set "Service base URL" to the URL of your oCIS instance. An instance with a trusted TLS certificate is required, e.g.
https://host.docker.internal:9200
- Set "Scopes included in a login request for offline access." to
openid offline_access email profile
- Save the changes
- To use webfinger for discovery of the oCIS server that is assigned to a specific user:
- Click on the "Configure endpoints" icon of the newly created service
- Create a new endpoint with the name
webfinger_endpoint
and the webfinger URL e.g.<service-base-url>/.well-known/webfinger
- Go to the "Manage repositories" page ("Site administration" > "Plugins" > "Repositories" > "ownCloud Infinite Scale repository")
- Create a new repository instance
- Choose a name you like
- Select the Oauth2 service you created before
- Save the settings
- Navigate to any page where there is a file picker e.g. "My courses" > "Create course" > "Course image"
- "Add" a new file
- Select the repository you have created earlier
- Click "Login in to your account"
- Go through the login / oauth process
- Now you should be able to see the content of your personal space and select files from there
❗ If extra dependencies were installed for development, make sure not to commit them to the repository! ❗
To reduce the setup steps specially when doing development and running automated tests these environment variables can be set to auto-provision the plugin:
MOODLE_OCIS_URL
,MOODLE_OCIS_CLIENT_ID
,MOODLE_OCIS_CLIENT_SECRET
,MOODLE_OCIS_LOGO_URL
to create OAuth 2 services and repository instance during installation. Note: the auto-provisioning will be triggered only if all ofMOODLE_OCIS_URL
,MOODLE_OCIS_CLIENT_ID
,MOODLE_OCIS_CLIENT_SECRET
variables are set.
To meet the moodle coding style, we are using phpcs with the moodle ruleset.
make test-php-style
make test-php-style-fix
Additional setup for UI TEST