1.1.7 • Published 3 years ago
@india-project/discord-oauth v1.1.7
India Project - oAuth2 - Discord
The project is meant to be used with express but we are always up for pr's
Example usage:
import { Client } from "@india-project/oauth-discord";
import express from "express";
const app = express();
const OauthClient = new Client({
client_id: "Client id here",
client_secret: "Client secret here",
version: "What version of the api you wish to use, example 8",
callback: "Client callback url here",
scopes: ["A string array of scopes go here"],
});
app.get("/auth", (req, res) =>
// The authenticate method takes 3 params, the req and res param from express route and a state of your choosing, example some idenfifyer of some sort
OauthClient.authenticate(req, res, "Identifyer/state here")
);
app.get("/callback", async (req, res) => {
const payload = await OauthClient.callback(req);
// The returned payload returns a user object, access and refresh token and the state you passed earlier
});
app.listen(5000, () => console.log("Server started on port 5000"));
Example payload data:
{
"options": {
"accessToken": "fiofuiehfuiehfuiheuifheuifhiuehfuidhf",
"refreshToken": "FJEHFYEfejihfwyehiuHIUFHuihUIh83re32",
"expiresIn": 432434,
"state": "My state",
"user": {
"options": {
"id": "163674707013402625",
"username": "Eskpil",
"avatar": "9d266991ee9afb097dc2ae4766ebf510",
"discriminator": "1212",
"publicFlags": 64,
"flags": 64,
"email": "example@example.com",
"verified": true,
"locale": "en-US",
"mfaEnabled": true
}
}
}
}
Example refresh method usage:
app.get("/newTokens", async (req, res) => {
// The refresh method takes one param, the refresh_token
const newTokens = await OauthClient.refresh("fjhrfewddjfhdfuhefhdsfs");
});
And example of the refresh method response:
{
"options": {
"accessToken": "jfierwhfuihreuigfheruihgeruihg",
"refreshToken": "fpjkwefohreugyergyergierhgergr",
"expiresIn": 235564
}
}
Innstallation
With yarn:
yarn add @india-project/discord-oauth
with npm:
npm i --save @india-project/discord-oauth