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
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',
redirectUri: `http://127.0.0.1:5004/callback`
}
KyberOauth2.initialize(clientConfig)
try {
const data = await KyberOauth2.getSession()
console.log(data.userInfo)
} catch (error) {
KyberOauth2.authenticate()
const data = await KyberOauth2.loginAnonymous()
console.log(data.userInfo)
}
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