Socket
Socket
Sign inDemoInstall

@kyberswap/oauth2

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kyberswap/oauth2

🛠 An SDK for authentication with Oauth2


Version published
Weekly downloads
13
increased by44.44%
Maintainers
1
Weekly downloads
 
Created
Source

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
   ...

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

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

FAQs

Package last updated on 01 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc