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

@hono-dev/auth-github

v0.0.1

Published

Github Authentication Strategy for Hono

Downloads

5

Readme

Logo

@hono-dev/auth-github

For more details: https://github.com/willin/sso

Useage

GitHub provides two types of Apps to utilize its API: the GitHub App and the OAuth App. To understand the differences between these apps, you can read this article from GitHub, helping you determine the type of App you should select.

Parameters

  • client_id:
    • Type: string.
    • Required.
    • Github App and Oauth App.
    • Your app client ID. You can find this value in the GitHub App settings or the OAuth App settings based on your App type. When developing Cloudflare Workers, there's no need to send this parameter. Just declare it in the .dev.vars file as GITHUB_ID=.
  • client_secret:
    • Type: string.
    • Required.
    • Github App and Oauth App.
    • Your app client secret. You can find this value in the GitHub App settings or the OAuth App settings based on your App type. When developing Cloudflare Workers, there's no need to send this parameter. Just declare it in the .dev.vars file as GITHUB_SECRET=.

      Do not share your client secret to ensure the security of your app.

  • scope:
    • Type: string[] | string.
    • Optional.
    • Oauth App.
    • Set of permissions to request the user's authorization to access your app for retrieving user information and performing actions on their behalf. Review all the scopes Github offers for utilizing their API on the Permissions page. For GitHub Apps, you select the scopes during the App creation process or in the settings.
  • oauthApp:
    • Type: boolean.
    • Optional.
    • Oauth App.
    • Set this value to true if your App is of the OAuth App type. Defaults to false.
  • redirect_uri:
    • Type: string.
    • Optional.
    • Oauth App.
    • Github can have multiple callback URLs. Defaults to c.req.url.When developing Cloudflare Workers, there's no need to send this parameter. Just declare it in the .dev.vars file as GITHUB_CALLBACK_URL=.

Authentication Flow

After the completion of the Github Auth flow, essential data has been prepared for use in the subsequent steps that your app needs to take.

githubAuth method provides 2 set key data:

  • github-token:
    • Access token to make requests to the Github API for retrieving user information and performing actions on their behalf.
    • Type:
      {
        access_token: string;
        expires_in?: number;  // -> only available for Oauth Apps
        refresh_token?: string;
        refresh_token_expires_in?: number;
        token_type: string;
        scope: GitHubScope[]; // -> Granted Scopes
      }
  • github-user:
    • User basic info retrieved from Github
    • Type:
      {
        login:  string
        id:  number
        node_id:  string
        avatar_url:  string
        gravatar_id:  string
        url:  string
        html_url:  string
        followers_url:  string
        following_url:  string
        gists_url:  string
        starred_url:  string
        subscriptions_url:  string
        organizations_url:  string
        repos_url:  string
        events_url:  string
        received_events_url:  string
        type:  string
        site_admin:  boolean
        name:  string
        company:  string
        blog:  string
        location:  string
        email:  string  |  null
        hireable:  boolean  |  null
        bio:  string
        twitter_username:  string
        public_repos:  number
        public_gists:  number
        followers:  number
        following:  number
        created_at:  string
        updated_at:  string
        private_gists:  number, // -> Github App
        total_private_repos:  number, // -> Github App
        owned_private_repos:  number, // -> Github App
        disk_usage:  number, // -> Github App
        collaborators:  number, // -> Github App
        two_factor_authentication:  boolean, // -> Github App
        plan: {
          name:  string,
          space:  number,
          collaborators:  number,
          private_repos:  number
        } // -> Github App
      }

Github App Example

import { Hono } from 'hono';
import { githubAuth } from '@hono-dev/auth-github';

const app = new Hono();

app.use(
  '/github',
  githubAuth({
    client_id: Bun.env.GITHUB_ID,
    client_secret: Bun.env.GITHUB_SECRET
  })
);

app.get('/github', (c) => {
  const token = c.get('github-token');
  const user = c.get('github-user');

  return c.json({
    token,
    user
  });
});

export default app;

OAuth App Example

import { Hono } from 'hono';
import { githubAuth } from '@hono-dev/auth-github';

const app = new Hono();

app.use(
  '/github',
  githubAuth({
    client_id: Bun.env.GITHUB_ID,
    client_secret: Bun.env.GITHUB_SECRET,
    scope: ['public_repo', 'read:user', 'user', 'user:email', 'user:follow'],
    oauthApp: true
  })
);

app.get('/github', (c) => {
  const token = c.get('github-token');
  const user = c.get('github-user');

  return c.json({
    token,
    user
  });
});

export default app;

赞助 Sponsor

维护者 Owner: Willin Wang

如果您对本项目感兴趣,可以通过以下方式支持我:

Donation ways:

许可证 License

Apache-2.0