API42Client
API42Client is a class that help you interacte with 42 school api and get users data
Installation
This is a Node.js module available through the
npm registry.
Before installing, download and install Node.js.
If this is a brand new project, make sure to create a package.json
first with
the npm init
command.
Installation is done using the
npm install
command:
$ npm install api42client
example file run.js
import Authenticator from "api42client";
const UID = "98a139943caaa7645f98b077445f8e84de4cb23e7668fb010a01b9c0ed20b8a4";
const SECRET = "b34df710754fbe173bfd202cd0bfdf05fcdc4dda3f22b4d76459a2a1e1c35f";
const REDIRECT_URI = "http://localhost:3000";
var app = new Authenticator(UID, SECRET, REDIRECT_URI);
var token = app.get_Access_token("85a7e9c0bdbb53d6583064846c087e5e499b6b523f0602c46d1d422078feaf77");
token.then((data) => {
console.log("======================== auth user Data =========================");
console.log(data);
console.log("========================= 42 user data ==========================");
app.get_user_data(data.access_token).then((data) => {
console.log(data);
console.log("=============================================================");
});
}).catch((err) => {
console.log(err);
});
Configuration
- Make sure you have install api42client package
npm i api42client
- Change UID in
Position -1-
with your values in 42 app (like in picture) - Change SECRET in
Position -2-
with your values in 42 app (like in picture) - Change REDIRECT_URI in
Position -3-
with your values in 42 app (like in picture)
User flow
- send the user to 42 site to authorize the app
[it is the link below REDIRECT URL in 42 api page]
- 42 api will redirect the user to the REDIRECT_URI with the code in query string
- get the code from the query string (
code=7a0c...5f5aa9bc
) - give it to get_Access_token function like sourcecode in
index.mjs
file
Running
node run.js
Finally Congratulations 🎉 you will get all user info from 42 api
License
MIT
Support
This package costs me time to make and maintain every time.
[I am very 😀 about every coffee!]