@creamery/oauth2client
v1.0.1
Published
A simple oauth2 client
Downloads
4
Readme
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)
...
}
...
})