Git Product home page Git Product logo

breadfish-oauth's Introduction

Breadfish OAuth

A simple library to use the Breadfish OAuth API in NodeJS.

Table of Contents

Installation

npm install breadfish-oauth

Usage

const BreadfishOAuth = require("breadfish-oauth");

Or if you want to use it with ES6:

import BreadfishOAuth from "breadfish-oauth/es6";

Example

const BreadfishOAuth = require("breadfish-oauth");
let oauth = new BreadfishOAuth("PROJECT_ID", "API_KEY");

Full example

// Always use try/catch when you use the library!
// Many of the functions can throw an error when you pass something invalid.
try {
    let oauth = new BreadfishOAuth("PROJECT_ID", "API_KEY"); // Creates a new oAuth instance (throws an error if the credentials are invalid)
    // Verifies the credentials. This is not required, but is advised,
    // because the generated Auth URL will not work if the credentials are wrong
    await oauth.checkCredentials();
    // Scopes
    let valid = BreadfishOAuth.isValidScope("test"); // Checks if the specified scope is valid (Returns boolean)
    let availableScopes = BreadfishOAuth.getValidScopes(); // All available scopes in an array of strings
    oauth.setScopes(availableScopes); // Sets an array of strings as the available scopes
    oauth.removeScope(availableScopes[0]); // Removes the specified scope
    oauth.clearScopes(); // Removes all scopes
    oauth.addScope(availableScopes[0]); // Adds a single scope

    // Redirect
    oauth.setRedirectURL("https://example.com"); // Sets the redirect url (has to match the domain in the project settings)

    // Getters (These don't have setters! Use the functions to set them)
    let scopes = oauth.scopes;
    let redirectURL = oauth.redirectURL;

    // Generate the Authentification URL
    let url = oauth.getAuthURL(); // Generates the auth url (Throws an error if the scopes are not set, or there is no redirect url set)
} catch (e) {
    console.error(e);
}

Support

Please open an issue for support.

License

MIT © Leon B.

breadfish-oauth's People

Contributors

leonmrbonnie avatar

Watchers

 avatar

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.