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

hapi-github-auth

v1.0.2

Published

GitHub Authentication for Hapi.js (v17+)

Downloads

1

Readme

hapi-github-auth

GitHub Authentication for Hapi.js (v17+)

😄

我们提供了可以直接运行的示例,在 /example 目录下面。

demo 运行方法:

  1. 配置 Client ID 和 Client Secret
  2. 在根目录下执行 node /example/server.js 即可快速启动
  3. 访问 http://localhost:3001/login
  4. 访问返回的 url 地址,成功授权后,即可看到授权账号的公开用户信息。

插件使用方法

setp1:

github 中新建APP,获取Client ID 和 Client Secret。

step2:

在您的 Hapi.js 项目中下载该插件。

npm install hapi-github-auth

step3:

在您的 Hapi.js 项目中引入此插件并且注册。

// 授权成功后的处理方法
const github_handler = require('./github_handler.js')

// 配置插件
const plugins = [{
    plugin: require('hapi-github-auth'),
    options: {
        SCOPE: 'user',
        handler: github_handler,
        BASE_URL: 'http://localhost:3001',
        GITHUB_CLIENT_ID: 'your github client id',
        GITHUB_CLIENT_SECRET: 'you githun client secret',
        GITHUB_AUTH_REDIRECT_URL: '/github_auth',
        PORT: 3001,
        GITHUB_HOSTNAME: 'github.com',
        GITHUB_API_HOSTNAME: 'api.github.com'
    }
}]

// ...

// 将插件注册到server中
await server.register(plugins)

step4:

在您的项目中添加一个路由,用来获取 github 授权登录的 url 地址

const loginRouter = [{
    path: '/login',
    method: 'get',
    handler: function (req, h) {
        // 点击这个url 就到    github 授权登录的页面
        var url = require('hapi-github-auth').plugin.login_url();
        return {
            url
        }
    }
}]

step5:

授权登录成功后,可以获得 access_token、用户信息等。在您配置的 handler 里面继续处理后面的逻辑即可。

// github_handler.js
const github_handler = function (req, h, access_json_token, userinfo) {
    // your handler ...
    return {
        access_json_token,
        userinfo
    }
}
module.exports = github_handler

配置项说明:


SCOPE: 授权方法

handler: 授权成功后的回调方法

BASE_URL: 项目基础url, 比如,'http://localhost:3001'

GITHUB_CLIENT_ID: your github client id

GITHUB_CLIENT_SECRET: your githun client secret

GITHUB_AUTH_REDIRECT_URL: 授权成功后的路径。 如,'/github_auth'

PORT: 项目端口号, 如,3001

GITHUB_HOSTNAME: 'github.com'

GITHUB_API_HOSTNAME: 'api.github.com


issue

遇到问题可以直接提 issue 。

国际化

目前文档只有中文,有兴趣的同学可以 pr 英文文档哦。

other

special give thanks to dwyl orgnization.

inspire from @dwyl