Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Moodle App Deep Linking: Difference between revisions

From MoodleDocs
m (Noeldemartin moved page Open the Moodle app from another app to Moodle App Deep Linking: Consistency)
(Clean up)
Line 1: Line 1:
{{Moodle App (Ionic 5)}}
{{Moodle App (Ionic 5)}}


== Overview ==


{{Moodle App version|3.7}}
== Overview ==
The Moodle app supports being launched using a Custom URL Scheme. In version 3.6.1 or older of the app, the format to do so was:
The Moodle app supports being launched using a Custom URL Scheme. In version 3.6.1 or older of the app, the format to do so was:
<syntaxhighlight lang="php">moodlemobile://link=https://mysite.es/mod/choice/view.php?id=8</syntaxhighlight>
However, in Moodle app 3.7.0 we introduced a better way to define these links. The new format will let you specify the URL to open, the username to use and also a token to authenticate the user.


Please notice that these links will only work if the app is installed in the device. E.g. if you click one of these links in Safari in an iOS device without the app installed, an error will be displayed.
<syntaxhighlight lang="text">
moodlemobile://link=https://mysite.es/mod/choice/view.php?id=8
</syntaxhighlight>
 
However, in Moodle app 3.7.0 we introduced a better way to define these links. The new format lets you specify the URL to open, the username to use and also a token to authenticate the user.


Please notice, if you are using a custom Moodle App you have to change the word "moodlemobile" to your custom URL scheme. If you are using a [https://moodle.com/branded-app BMA (Branded Moodle App)], please contact your [https://moodle.com/services Moodle Service Provider (Moodle partner)] for this information.
Please notice that these links will only work if the app is installed in the device. For example, if you click one of these links in Safari in an iOS device without the app installed, an error will be displayed.
 
Please notice, if you are using a custom Moodle App you have to change <code>moodlemobile://</code> to your custom URL scheme. If you are using a [https://moodle.com/branded-app BMA (Branded Moodle App)], please contact your [https://moodle.com/services Moodle Service Provider (Moodle partner)] for this information.


== Format ==
== Format ==
The new format to create the links is like this:
 
<syntaxhighlight lang="php">moodlemobile://https://username@domain.com?token=TOKEN&privatetoken=PRIVATETOKEN&redirect=http://domain.com/course/view.php?id=2</syntaxhighlight>
The new format to create the links is the following:
The only data required is the base URL of your site (in the example above, <syntaxhighlight lang="php">https://domain.com</syntaxhighlight>).
 
<syntaxhighlight lang="text">
moodlemobile://https://username@domain.com?token=TOKEN&privatetoken=PRIVATETOKEN&redirect=http://domain.com/course/view.php?id=2
</syntaxhighlight>
 
The only data required is the base URL of your site (in the example above, <code>https://domain.com</code>).
 
=== Site URL ===
=== Site URL ===
As mentioned above, this is the only required param. It should be the base URL of the site (wwwroot). For example, you can use this URL to open your site in the app:
 
<syntaxhighlight lang="php">moodlemobile://https://domain.com</syntaxhighlight>
As mentioned above, this is the only required parameter. It should be the base URL of the site (wwwroot). For example, you can use this URL to open your site in the app:
In the example above, if the site <syntaxhighlight lang="php">https://domain.com</syntaxhighlight> isn't stored in the app, the user will be redirected to the credentials screen to access the site.
 
<syntaxhighlight lang="text">
moodlemobile://https://domain.com
</syntaxhighlight>
 
In the example above, if the <code>https://domain.com</code> site isn't stored in the app, the user will be redirected to the credentials screen to access the site.
 
=== Username ===
=== Username ===
If you want the app to be opened with a certain username you can specify it in the URL:
If you want the app to be opened with a certain username you can specify it in the URL:
<syntaxhighlight lang="php">moodlemobile://https://username@domain.com</syntaxhighlight>
 
In the example above, if the user <syntaxhighlight lang="php">username</syntaxhighlight> and the site <syntaxhighlight lang="php">https://domain.com</syntaxhighlight> aren't stored in the app, the user will be sent to the credentials screen to access the site (the username input will be prepopulated, but the user will be able to change it if he wants to). If the app has several users of this site stored, including "username", the right user will be loaded.
<syntaxhighlight lang="text">
moodlemobile://https://username@domain.com
</syntaxhighlight>
 
In the example above, if the <code>username</code> user and the <code>https://domain.com</code> site aren't stored in the app, the user will be sent to the credentials screen to access the site (the username input will be prepopulated, but the user will be able to change it if he wants to). If the app has several users of this site stored, including "username", the right user will be loaded.
 
=== Token and Private token ===
=== Token and Private token ===
If you specify a token in the URL, the user will be authenticated automatically in the app. This is really useful for external apps and systems, e.g. you can use this feature for SSO systems. The user token can be found in the database table "mdl_external_tokens".


The private token is used by the app to auto-login the user in the browser, and it will only be used if you also specify a token in the URL. If you specify a privatetoken but not a token, the privatetoken will be ignored. The private token can also be found in the database table "mdl_external_tokens".
If you specify a token in the URL, the user will be authenticated automatically in the app. This is really useful for external apps and systems. For example, you can use this feature for SSO systems. The user token can be found in the database table <code>mdl_external_tokens</code>.
 
The private token is used by the app to auto-login the user in the browser, and it will only be used if you also specify a token in the URL. If you specify a private token but not a token, the private token will be ignored. The private token can also be found in the database table <code>mdl_external_tokens</code>.


It isn't recommended to include the token and privatetoken in links that will be rendered by a browser or apps that can be inspected. Please notice that anyone with the token will be able to authenticate as the user the token belongs to.
It isn't recommended to include the token and private token in links that will be rendered by a browser or apps that can be inspected. Please notice that anyone with the token will be able to authenticate as the user the token belongs to.


Example:
Example:
<syntaxhighlight lang="php">moodlemobile://https://domain.com?token=TOKEN&privatetoken=PRIVATETOKEN</syntaxhighlight>
 
The token has priority over the username parameter. E.g. if you specify username "u1" but the token belongs to user "u2", the user u2 will be authenticated in the app.
<syntaxhighlight lang="text">
moodlemobile://https://domain.com?token=TOKEN&privatetoken=PRIVATETOKEN
</syntaxhighlight>
 
The token has priority over the username parameter. For example, if you specify username "u1" but the token belongs to user "u2", the user u2 will be authenticated in the app.
 
=== Redirect ===
=== Redirect ===
The redirect parameter indicates which page you want to open in the app. Example:
<syntaxhighlight lang="php">moodlemobile://https://domain.com?redirect=http://domain.com/course/view.php?id=2</syntaxhighlight>
This link will open the course with ID=2 in the app. Please notice that the app doesn't support all Moodle URLs, only some of them are supported.


The redirect URL should belong to the same site as the base URL. E.g. if the base URL is <syntaxhighlight lang="php">http://domain.com</syntaxhighlight> but the redirect is <syntaxhighlight lang="php">http://anothersite.com/...</syntaxhighlight>, an error will be displayed.
The redirect parameter indicates which page you want to open in the app:
 
<syntaxhighlight lang="text">
moodlemobile://https://domain.com?redirect=http://domain.com/course/view.php?id=2
</syntaxhighlight>
 
This link will open the course with id 2 in the app. Please notice that the app doesn't support all Moodle URLs, only some of them are supported.
 
The redirect URL should belong to the same site as the base URL. For example, if the base URL is <code>http://domain.com</code> but the redirect is <code>http://anothersite.com/...</code>, an error will be displayed.
 
The redirect parameter can be a relative URL based on the base URL. The example above can also be written like this:
The redirect parameter can be a relative URL based on the base URL. The example above can also be written like this:
<syntaxhighlight lang="php">moodlemobile://https://domain.com?redirect=/course/view.php?id=2</syntaxhighlight>
 
<syntaxhighlight lang="text">
moodlemobile://https://domain.com?redirect=/course/view.php?id=2
</syntaxhighlight>
 
== See also ==
== See also ==
[https://github.com/EddyVerbruggen/Custom-URL-scheme Custom URL Scheme Cordova plugin used by the app]
 
* [https://github.com/EddyVerbruggen/Custom-URL-scheme Custom URL Scheme Cordova plugin used by the app].

Revision as of 12:52, 15 September 2021


Overview

The Moodle app supports being launched using a Custom URL Scheme. In version 3.6.1 or older of the app, the format to do so was:

moodlemobile://link=https://mysite.es/mod/choice/view.php?id=8

However, in Moodle app 3.7.0 we introduced a better way to define these links. The new format lets you specify the URL to open, the username to use and also a token to authenticate the user.

Please notice that these links will only work if the app is installed in the device. For example, if you click one of these links in Safari in an iOS device without the app installed, an error will be displayed.

Please notice, if you are using a custom Moodle App you have to change moodlemobile:// to your custom URL scheme. If you are using a BMA (Branded Moodle App), please contact your Moodle Service Provider (Moodle partner) for this information.

Format

The new format to create the links is the following:

moodlemobile://https://username@domain.com?token=TOKEN&privatetoken=PRIVATETOKEN&redirect=http://domain.com/course/view.php?id=2

The only data required is the base URL of your site (in the example above, https://domain.com).

Site URL

As mentioned above, this is the only required parameter. It should be the base URL of the site (wwwroot). For example, you can use this URL to open your site in the app:

moodlemobile://https://domain.com

In the example above, if the https://domain.com site isn't stored in the app, the user will be redirected to the credentials screen to access the site.

Username

If you want the app to be opened with a certain username you can specify it in the URL:

moodlemobile://https://username@domain.com

In the example above, if the username user and the https://domain.com site aren't stored in the app, the user will be sent to the credentials screen to access the site (the username input will be prepopulated, but the user will be able to change it if he wants to). If the app has several users of this site stored, including "username", the right user will be loaded.

Token and Private token

If you specify a token in the URL, the user will be authenticated automatically in the app. This is really useful for external apps and systems. For example, you can use this feature for SSO systems. The user token can be found in the database table mdl_external_tokens.

The private token is used by the app to auto-login the user in the browser, and it will only be used if you also specify a token in the URL. If you specify a private token but not a token, the private token will be ignored. The private token can also be found in the database table mdl_external_tokens.

It isn't recommended to include the token and private token in links that will be rendered by a browser or apps that can be inspected. Please notice that anyone with the token will be able to authenticate as the user the token belongs to.

Example:

moodlemobile://https://domain.com?token=TOKEN&privatetoken=PRIVATETOKEN

The token has priority over the username parameter. For example, if you specify username "u1" but the token belongs to user "u2", the user u2 will be authenticated in the app.

Redirect

The redirect parameter indicates which page you want to open in the app:

moodlemobile://https://domain.com?redirect=http://domain.com/course/view.php?id=2

This link will open the course with id 2 in the app. Please notice that the app doesn't support all Moodle URLs, only some of them are supported.

The redirect URL should belong to the same site as the base URL. For example, if the base URL is http://domain.com but the redirect is http://anothersite.com/..., an error will be displayed.

The redirect parameter can be a relative URL based on the base URL. The example above can also be written like this:

moodlemobile://https://domain.com?redirect=/course/view.php?id=2

See also