summaryrefslogtreecommitdiff
path: root/alarm/node_modules/pronote-api/src/cas/generics/kdecole-wayf.js
blob: 7d20163833db6345e57058fdb7290aa117450ad9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const jsdom = require('jsdom');

const { getDOM, submitForm, extractStart } = require('../api');
const aten = require('./aten');

async function login({ url, account, username, password, casUrl, idp, atenURL })
{
    if (idp && !idp.includes('parent_eleve')) {
        idp += '_parent_eleve';
    }

    casUrl = `https://${casUrl}/`;

    const jar = new jsdom.CookieJar();
    let dom = await getDOM({
        url: `${casUrl}login?${idp ? `selection=${idp}&` : ''}service=${encodeURIComponent(url)}`,
        jar
    });

    if (atenURL) {
        dom = await submitForm({
            dom,
            jar,
            runScripts: !!atenURL,
            hook: atenURL && aten.hook,
            actionRoot: casUrl
        });

        await aten.submit({ dom, jar, username, password, atenURL });
    } else {
        dom.window.document.getElementById('username').value = username;
        dom.window.document.getElementById('password').value = password;

        await submitForm({
            actionRoot: casUrl,
            dom,
            jar,
            asIs: true
        });
    }

    return extractStart(await getDOM({ url: url + account.value + '.html', jar, asIs: true }));
}

module.exports = login;