Giter VIP home page Giter VIP logo

github-oauth-prompt's Introduction

github-oauth-prompt Build Status

Easy creation of GitHub OAuth tokens.

Getting Started

Install the module with: npm install github-oauth-prompt

var oauth = require('github-oauth-prompt');
oauth({name: 'my-token'}, function (token) {
    // Now you have a token.
});

Documentation

(Coming soon)

See Examples

Examples

In all examples below, callback is a function accepting two parameters: error, and response.

// Prompt for username, password, two-factor auth code if required,
// and return to the callback a GitHub token with basic scope.
oauth({
    name: 'moonrise-kingdom'
}, callback);
// Prompt for a token for read/write access to all repositories
// and organisations and write access to Gists.
// More scopes: https://developer.github.com/v3/oauth/#scopes
oauth({
    name: 'rushmore',
    scopes: ['repo', 'gist']
}, callback);
// Set prompt messages.
oauth({
    name: 'the-life-aquatic',
    prompt: {
        username: 'Enter username:',
        password: 'Enter password:',
        code: 'Enter two-factor authorisation code'
    }
}, callback);
// Use own prompt. Must deal with two-factor authentication.
// Ask for username and password and store in an object. For this example, and
// to avoid getting bogged down in callback-hell, we have them already available.
var auth = {
    username: 'Margot',
    password: 'RichieLovesMe'
};
// Setup a function to call oauth with a code.
function getToken (code) {
    // Get a token with a two-factor authentication code.
    var authOptions = {
        name: 'the-royal-tenenbaums'
        username: auth.username,
        password: auth.password,
    };
    if (code) {
        authOptions.code = code;
    }
    oauth(authOptions, function (err, token) {
        console.log(token);
    });
}
// Test to see if a code is required for a given username and password.
oauth.requiresCode(auth, function (err, hasTwoFactorAuth) {
    if (!hasTwoFactorAuth) {
        // No need for a code.
        getToken();
    } else {
        // You need to get a two-factor authentication code from
        // the user.
        myCodePrompt(function (err, code) {
            getToken(code);
        });
    }
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

# Requirements
npm install -g grunt-cli
# Dev
npm install && grunt

Release History

  • v0.1.0 Bottle Rocket

License

Copyright (c) 2014 Henry Blyth. Licensed under the MIT license.

github-oauth-prompt's People

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.