diff --git a/examples/biome_oauth2.ts b/examples/biome_oauth2.ts index ae1c790..1f32381 100644 --- a/examples/biome_oauth2.ts +++ b/examples/biome_oauth2.ts @@ -1,10 +1,11 @@ -import { oauth2_authorize, oauth2_token, oauth2_userinfo } from "../src"; +import { cas_login, cas_oauth2_authorize, cas_oauth2_token, cas_oauth2_userinfo } from "../src"; import { credentials } from "./_credentials"; void async function main () { - const code = await oauth2_authorize(credentials); - const { access_token } = await oauth2_token(code); - const { email, name, sub } = await oauth2_userinfo(access_token); + const cas_token = await cas_login(credentials.username, credentials.password); + const code = await cas_oauth2_authorize(cas_token); + const { access_token } = await cas_oauth2_token(code); + const { email, name, sub } = await cas_oauth2_userinfo(access_token); console.log("Logged to", sub, "with email", email, "and name", name); }(); diff --git a/examples/events_calendar_id.ts b/examples/events_calendar_id.ts index 01f4f62..757ac11 100644 --- a/examples/events_calendar_id.ts +++ b/examples/events_calendar_id.ts @@ -1,11 +1,12 @@ -import { get_events_by_calendar_id, login_check, oauth2_authorize, oauth2_token } from "../src"; +import { cas_login, get_events_by_calendar_id, login_check, cas_oauth2_authorize, cas_oauth2_token } from "../src"; import { credentials } from "./_credentials"; const CALENDAR_ID = ""; void async function main () { - const code = await oauth2_authorize(credentials); - const { access_token } = await oauth2_token(code); + const cas_token = await cas_login(credentials.username, credentials.password); + const code = await cas_oauth2_authorize(cas_token); + const { access_token } = await cas_oauth2_token(code); const { token } = await login_check(access_token); const events = await get_events_by_calendar_id(token, { diff --git a/examples/external_service_ticket.ts b/examples/external_service_ticket.ts new file mode 100644 index 0000000..31810e4 --- /dev/null +++ b/examples/external_service_ticket.ts @@ -0,0 +1,18 @@ +import { credentials } from "./_credentials"; +import { cas_login, cas_service, CAS_EXTERNAL_SERVICES } from "../src"; + +/** + * In this example, we'll see how we can get a ticket for an external service. + * An external service is like a Moodle instance, a calendar, or a forum. + * + * We'll use the CAS to get those tickets. + */ +void async function main () { + // 1. get an authenticated token from the CAS. + const cas_token = await cas_login(credentials.username, credentials.password); + + // 2. let's get a ticket for any service inside "CAS_EXTERNAL_SERVICES" constant. + const iut_moodle_ticket = await cas_service(cas_token, CAS_EXTERNAL_SERVICES.IUT_COMMUNITY_MOODLE); + console.log(iut_moodle_ticket); +}(); + diff --git a/examples/moodle.ts b/examples/moodle.ts index bb0a63c..3d15f85 100644 --- a/examples/moodle.ts +++ b/examples/moodle.ts @@ -1,11 +1,13 @@ -import { get_moodle_courses, login_check, oauth2_authorize, oauth2_token } from "../src"; +import { cas_login, get_moodle_courses, login_check, cas_oauth2_authorize, cas_oauth2_token } from "../src"; import { credentials } from "./_credentials"; void async function main () { - const code = await oauth2_authorize(credentials); - const { access_token } = await oauth2_token(code); + const cas_token = await cas_login(credentials.username, credentials.password); + const code = await cas_oauth2_authorize(cas_token); + const { access_token } = await cas_oauth2_token(code); const { token } = await login_check(access_token); + // Get Moodle courses from Biome API. const courses = await get_moodle_courses(token, true); console.log(courses); }(); diff --git a/examples/preferences.ts b/examples/preferences.ts index e05199f..18e8f73 100644 --- a/examples/preferences.ts +++ b/examples/preferences.ts @@ -1,9 +1,10 @@ -import { login_check, oauth2_authorize, oauth2_token, preferences_by_properties } from "../src"; +import { cas_login, login_check, cas_oauth2_authorize, cas_oauth2_token, preferences_by_properties } from "../src"; import { credentials } from "./_credentials"; void async function main () { - const code = await oauth2_authorize(credentials); - const { access_token } = await oauth2_token(code); + const cas_token = await cas_login(credentials.username, credentials.password); + const code = await cas_oauth2_authorize(cas_token); + const { access_token } = await cas_oauth2_token(code); const { token } = await login_check(access_token); const userApplications = await preferences_by_properties(token, "userApplications"); diff --git a/examples/subscribed.ts b/examples/subscribed.ts index c1c9f0b..0260b07 100644 --- a/examples/subscribed.ts +++ b/examples/subscribed.ts @@ -1,9 +1,10 @@ -import { get_subscribed_by_username, login_check, oauth2_authorize, oauth2_token } from "../src"; +import { cas_login, get_subscribed_by_username, login_check, cas_oauth2_authorize, cas_oauth2_token } from "../src"; import { credentials } from "./_credentials"; void async function main () { - const code = await oauth2_authorize(credentials); - const { access_token } = await oauth2_token(code); + const cas_token = await cas_login(credentials.username, credentials.password); + const code = await cas_oauth2_authorize(cas_token); + const { access_token } = await cas_oauth2_token(code); const { token } = await login_check(access_token); const subscribed = await get_subscribed_by_username(token); diff --git a/examples/user_profile.ts b/examples/user_profile.ts index 38f9b45..a3969a6 100644 --- a/examples/user_profile.ts +++ b/examples/user_profile.ts @@ -1,9 +1,10 @@ -import { oauth2_authorize, oauth2_token, login_check, get_user_profile } from "../src"; +import { cas_oauth2_authorize, cas_oauth2_token, login_check, get_user_profile, cas_login } from "../src"; import { credentials } from "./_credentials"; void async function main () { - const code = await oauth2_authorize(credentials); - const { access_token } = await oauth2_token(code); + const cas_token = await cas_login(credentials.username, credentials.password); + const code = await cas_oauth2_authorize(cas_token); + const { access_token } = await cas_oauth2_token(code); const { token } = await login_check(access_token); const profile = await get_user_profile(token, credentials.username);