1.0.1 • Published 7 years ago

@creamery/oauth2client v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Oauth2Client

A simple oauth2 client

Usage

const Oauth2Client = require('@creamery/oauth2client')

const oauth2Client = new Oauth2Client({
  baseUrl,
  oauthPath,
  tokenPath,
  redirectURI,
  appId,
  appSecret
})

// and then you can use it like the code below
app.use(async (ctx, next) => {
  ...
  // here assume that is the code
  if (ctx.query.code) {
    const body = oauth2Client.requestToken(code)
    ctx.session.accessToken = body.access_token
    // if calling requestToken is failed,
    // it will throw the ERROR. You can catch it.
  }
  ...

  if (!ctx.session.accessToken) {
    oauth2Client.redirectToAuthorizedURI(ctx)
    ...
  }
  ...
})