2.2.2 • Published 2 years ago

api42client v2.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

API42Client

API42Client is a class that help you interacte with 42 school api and get users data

NPM Version NPM Install Size NPM Downloads

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";

// you can see the attached screen shot to know where get this variables
const UID          = "98a139943caaa7645f98b077445f8e84de4cb23e7668fb010a01b9c0ed20b8a4"; // Position -1-
const SECRET       = "b34df710754fbe173bfd202cd0bfdf05fcdc4dda3f22b4d76459a2a1e1c35f"; // Position -2-
const REDIRECT_URI = "http://localhost:3000"; // Position -3-

// 42 authenticator instance
var app = new Authenticator(UID, SECRET, REDIRECT_URI);

// after send the user to 42 site to authorize the app [example of 42 site: https://api.intra.42.fr/oauth/authorize?client_id=98a139f98b077445f8e84de4cb23e7668fb010a01b9c0ed20b8a4&redirect_uri=http%3A%2F%2Flocalhost%3A3000&response_type=code]
// 42 redirect the user to the REDIRECT_URI (in this example is: http://localhost:3000) with the code in query string
// like that: http://localhost:3000/?code=7a0cb1a9c5b0fd31a0eb9c5f854fc2386b1edc2179f73c76904d65f5aae4e9bc
// get the code from the query string (code=7a0cb1a9c5b0fd31a0eb9c5f854fc2386b1edc2179f73c76904d65f5aae4e9bc)
// and give it to get_Access_token function like below
var token = app.get_Access_token("85a7e9c0bdbb53d6583064846c087e5e499b6b523f0602c46d1d422078feaf77");

token.then((data) => {
	// get the acces token of the user
	console.log("======================== auth user Data =========================");
	console.log(data);
	console.log("========================= 42 user data ==========================");
	// get the user info from 42 api
	app.get_user_data(data.access_token).then((data) => {
		console.log(data);
		console.log("=============================================================");
	});
}).catch((err) => {
	console.log(err);
});

Configuration

  1. Make sure you have install api42client package npm i api42client
  2. Change UID in Position -1- with your values in 42 app (like in picture)
  3. Change SECRET in Position -2- with your values in 42 app (like in picture)
  4. Change REDIRECT_URI in Position -3- with your values in 42 app (like in picture)

User flow

  1. send the user to 42 site to authorize the app it is the link below REDIRECT URL in 42 api page
  2. 42 api will redirect the user to the REDIRECT_URI with the code in query string
  3. get the code from the query string (code=7a0c...5f5aa9bc)
  4. 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!

2.1.2

2 years ago

2.0.3

2 years ago

2.1.1

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.2.2

2 years ago

2.0.4

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago