npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

github-web-application-flow

v1.0.2

Published

Implementation of the Web Application Flow on GitHub

Downloads

16

Readme

github-web-application-flow

Build Status Coverage Status

Implementation for GitHub OAuth Web Application Flow

What's this?

This is an implementation for GitHub Authorizing OAuth Apps by Web Application Flow. This package is intended to use in CLI for users to authenticate GitHub OAuth Apps. You can get Access Tokens from GitHub with scopes you requested.

How to install

  1. Create a new GitHub OAuth App (see this instruction).

  2. Copy your Client ID & Client Secret from the App's setting (see Developer applications).

  3. Install from npm.

    npm i -S github-web-application-flow
  4. Setup scripts (see full examples in examples/ dir).

    const { webAppFlow } = require('github-web-application-flow')
    
    const accessToken = await webAppFlow({
      clientId: 'fooClientId',
      clientSecret: 'fooClientSecret'
    })
    
    console.log(`token got: ${accessToken}`)

Configuration

/**
 * WebAppFlowOptions is used to initialize the main func: webAppFlow().
 */
export interface WebAppFlowOptions {
  /**
   * Client ID of the App you set on GitHub.
   */
  clientId: string
  /**
   * Client Secret of the App you set on GitHub.
   */
  clientSecret: string
  /**
   * The name of this application. (default: 'My App')
   */
  name?: string
  /**
   * The base URL of GitHub API v3. You should set this for GitHub Enterprise.
   * (ex. 'https://github.example.com') (default: 'https://github.com')
   */
  baseUrl?: string
  /**
   * A port number used for a server in local to obtain the Authorization Code
   * for requests from GitHub. (default: 8080)
   */
  port?: number
  /**
   * A space-separated value that represents scopes you want to give to access
   * tokens. (default: "repo user")
   */
  scope?: string
  /**
   * A timeout to wait for getting an Authorization Code from GitHub. This
   * includes the user's interaction (sign-in, authentication, etc.), and so
   * takes a bit long. (default: 600000 (= 10 minutes))
   */
  codeTimeout?: number
  /**
   * A timeout to wait for getting an Access Token from GitHub. (default: 60000
   * (= 1 minutes))
   */
  tokenTimeout?: number
  /**
   * Show logs verbosely. For example, it shows the URL to open with messages.
   * If false, it works silently. (default: true)
   */
  verbose?: boolean
  /**
   * An instance like https.Agent. This is the same as the option in
   * AxiosRequestConfig. By this, you can use a http/https/socks proxy to
   * exchange an Authorization Code to an access token (see examples in
   * examples/ dir or README).
   */
  httpsAgent?: any
}

Troubleshooting

What about GitHub Enterprise?

You can use your own domain for GitHub Enterprise by the baseUrl option.

const accessToken = await webAppFlow({
 clientId: 'fooClientId',
 clientSecret: 'fooClientSecret',
 baseUrl: 'github.your-domain.com'
})

Can I access to the Internet with proxies?

You can use the httpsAgent option for this. Set agents for this such as socks-proxy-agent, https-proxy-agent, etc.

const SocksProxyAgent = require('socks-proxy-agent')

const accessToken = await webAppFlow({
 clientId: 'fooClientId',
 clientSecret: 'fooClientSecret',
 httpsAgent: new SocksProxyAgent('socks://localhost:1080')
})

others?

Issue at GitHub repo.

LICENSE

MIT License

Authors