summaryrefslogtreecommitdiff
path: root/includes/external/school/node_modules/pronote-api/src/cas/toutatice.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2023-02-23 19:34:56 +0100
committerMinteck <contact@minteck.org>2023-02-23 19:34:56 +0100
commit3d1cd02f27518f1a04374c7c8320cd5d82ede6e9 (patch)
tree75be5fba4368472fb11c8015aee026b2b9a71888 /includes/external/school/node_modules/pronote-api/src/cas/toutatice.js
parent8cc1f13c17fa2fb5a4410542d39e650e02945634 (diff)
downloadpluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.gz
pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.tar.bz2
pluralconnect-3d1cd02f27518f1a04374c7c8320cd5d82ede6e9.zip
Updated 40 files, added 37 files, deleted 1103 files and renamed 3905 files (automated)
Diffstat (limited to 'includes/external/school/node_modules/pronote-api/src/cas/toutatice.js')
-rw-r--r--includes/external/school/node_modules/pronote-api/src/cas/toutatice.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/includes/external/school/node_modules/pronote-api/src/cas/toutatice.js b/includes/external/school/node_modules/pronote-api/src/cas/toutatice.js
new file mode 100644
index 0000000..84c10b0
--- /dev/null
+++ b/includes/external/school/node_modules/pronote-api/src/cas/toutatice.js
@@ -0,0 +1,74 @@
+const jsdom = require('jsdom');
+const axioRequest = require('../axioRequest')
+
+const { getDOM, submitForm, extractStart } = require('./api');
+const educonnect = require('./generics/educonnect');
+const querystring = require('querystring');
+const http = require('../http');
+
+async function login(url, account, username, password) {
+ const jar = new jsdom.CookieJar();
+ let dom = await getDOM({
+ url: 'https://www.toutatice.fr/portail/auth/pagemarker/2/MonEspace',
+ jar
+ });
+
+ dom = await submitForm({
+ dom,
+ jar,
+ actionRoot: 'https://www.toutatice.fr/wayf/',
+ extraParams: {
+ // eslint-disable-next-line camelcase
+ _saml_idp: 'educonnect'
+ }
+ });
+ dom = await educonnect({ dom, jar, url, account, username, password });
+
+ let redirectURL = dom.window.document.getElementsByTagName('a')[0].href
+
+ let response = await axioRequest({
+ url: redirectURL,
+ jar
+ })
+
+ redirectURL = getOrigin(redirectURL) + response.headers.location
+
+ const parsed = querystring.parse(redirectURL.split('?')[1])
+ const conversation = parsed.conversation
+ const sessionid = parsed.sessionid
+
+ // eslint-disable-next-line max-len
+ redirectURL = `${getOrigin(redirectURL)}/idp/Authn/RemoteUser?conversation=${conversation}&redirectToLoaderRemoteUser=0&sessionid=${sessionid}`
+
+ response = await axioRequest({
+ url: redirectURL,
+ jar
+ })
+ // eslint-disable-next-line max-len
+ const remoteUserParsed = response.data.match(/<conversation>(.+)<\/conversation><uidInSession>(.+)<\/uidInSession>/u)
+
+ const remoteUserConversation = remoteUserParsed[1]
+ const uidInSession = remoteUserParsed[2]
+
+ // eslint-disable-next-line max-len
+ redirectURL = `${getOrigin(redirectURL)}/idp/Authn/RemoteUser?conversation=${remoteUserConversation}&uidInSession=${uidInSession}&sessionid=${sessionid}`
+
+ response = await http({
+ url: redirectURL,
+ jar,
+ followRedirects: true
+ })
+
+ return extractStart(await getDOM({
+ url: `${url}${account.value}.html`,
+ jar,
+ asIs: true
+ }))
+}
+
+function getOrigin(url) {
+ const noProtocol = url.substring(url.indexOf('/') + 2);
+ return url.substring(0, url.indexOf('/')) + '//' + noProtocol.substring(0, noProtocol.indexOf('/'));
+}
+
+module.exports = login;