Skip to content

Commit

Permalink
docs(examples): use new syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Jun 18, 2024
1 parent 0365cf0 commit 06704d7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 19 deletions.
9 changes: 5 additions & 4 deletions examples/biome_oauth2.ts
Original file line number Diff line number Diff line change
@@ -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);
}();
7 changes: 4 additions & 3 deletions examples/events_calendar_id.ts
Original file line number Diff line number Diff line change
@@ -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, {
Expand Down
18 changes: 18 additions & 0 deletions examples/external_service_ticket.ts
Original file line number Diff line number Diff line change
@@ -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);
}();

8 changes: 5 additions & 3 deletions examples/moodle.ts
Original file line number Diff line number Diff line change
@@ -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);
}();
7 changes: 4 additions & 3 deletions examples/preferences.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
7 changes: 4 additions & 3 deletions examples/subscribed.ts
Original file line number Diff line number Diff line change
@@ -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);

Expand Down
7 changes: 4 additions & 3 deletions examples/user_profile.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 06704d7

Please sign in to comment.