Code Monkey home page Code Monkey logo

oauth-cord's Introduction

OAuth-Cord

A simple library to lighten and quicken the use of discord's oauth2
img

Docs

Lets get started with using OAuth-cord!

Set Up

First we require the oauth-cord package. Then create a new instance of a Client which gives us access to multiple methods!

const OAuthCord = require("oauth-cord");
const client = new OAuthCord.Client();

Setting some params

Next we need to tell our client some things like a redirctUrl and some scopes.

const OAuthCord = require("oauth-cord");
const client = new OAuthCord.Client();

client.setRedirect("http://localhost:8080/login"); // Sets for URL to redirect to after authorizing

client.setScopes(["identitfy", "guilds"]); // Set the scopes

Methods

Now we get to the fun part!

getToken()

When you authorize the app you will get a code. You use that code to get an access token. Note: this method is async so use we use await here.

const token = await client.getToken(code); // pass code as param

getUser()

This method lets us get basic user info! Note: If you add the email scope you will also get the users email in the user object.

const token = await client.getToken(code); 

client.getUser(token); // set token you got as a param

getUserConnections()

Use this to get a list of a users profile connections.

const token = await client.getToken(code); 

client.getUserConnections(token);

getUserGuilds()

This method returns the guilds a user is in.

const token = await client.getToken(code); 

client.getUserGuilds(token);

addUserGuild()

Adds a user to a choosen guild! Note: You need to create bot for your discord app and have it in the server your trying to invite users to with the "CREATE_INSTANT_INVITE" permission for this to work.

const token = await client.getToken(code); 

client.addUserGuild(token, botToken, serverId);
// pass token, botToken, and serverId are params

And thats it! Thats all the methods for now.

Contributing

Feel free to contribute to this project by opening a pull request on github. If you have any sugestions or issues open up a issue on github!

Bye!

oauth-cord's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

oauth-cord's Issues

License

I'd say having a licence is a good idea, you can find one here: https://choosealicense.com/.

Some good suggestions would be:

If not one of them then any license you like will do! It's nice to know where and how a project can be used.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.