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

@kyberswap/oauth2

v1.0.2

Published

🛠 An SDK for authentication with Oauth2

Downloads

92

Readme

Sdk authentication

  • Support sign in with google, email, ethereum, anonymous
  • Provide functions (KyberOauth2Api) to call API, auto attach access token, refresh token if expired

How to install local

  • Create file .npmrc in root folder, with content:
@kybernetwork:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=your_token
  • Visit https://github.com/settings/tokens to create Classic Token if you don't have (at least has role read:packages)
  • Ping admin to add to whitelist https://github.com/orgs/KyberNetwork/packages/npm/oauth2/settings
  • Run npm install @kybernetwork/oauth2

Install via git workflow

  • Add registry-url,scope and NODE_AUTH_TOKEN
   ...
   - name: Set up Node.js 14.x
        uses: actions/setup-node@v1
        with:
          node-version: 14.x
          registry-url: 'https://npm.pkg.github.com'
          scope: '@kybernetwork'
   ...

   - name: Install dependencies
      uses: bahmutov/npm-install@HEAD
      env:
         NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} ### authen npm
   ...
  • Add your repo to Manage Actions access in this link https://github.com/orgs/KyberNetwork/packages/npm/oauth2/settings

How to use

Initialize SDK

  • Make sure call these lines once
import KyberOauth2 from '@kybernetwork/oauth2'

const clientConfig = {
  clientId:'b6f36b76-77b3-4f67-b756-1e49df71fda3', // register with our admin to have an id
  redirectUri: `http://127.0.0.1:5004/callback` // redirect to this url after successful sign-in. (optional)
}

KyberOauth2.initialize(clientConfig)

try {
  const data = await KyberOauth2.getSession()
  console.log(data.userInfo)  // user already login
} catch (error) {
  KyberOauth2.authenticate() // it will redirect you to login gateway to sign in with google/ethereum/email/...

  // or sign in anonymous
  const data = await KyberOauth2.loginAnonymous()
  console.log(data.userInfo) // this is anonymous user info
}

Call protected API with SDK

  • Make sure to Initialize SDK first
  • Use KyberOauth2Api.get(...), KyberOauth2Api.post(...) and KyberOauth2Api.call(...) instead of cal axios or fetch
  • KyberOauth2Api will attach access token and it will auto refresh token if token expired.

How to publish this package

  • Create file .npmrc in root folder, with content same as above
  • Update version in package.json
  • Run npm publish
  • Check here https://github.com/KyberNetwork/kyber-oauth2-sdk/pkgs/npm/oauth2

Development Mode

  • KyberOauth2.initialize({ mode: DEVELOPMENT_MODE, ... })
  • Please set mode to development or staging if you want to test, if not provided, mode will be production