microauth-vkontakte

1.1.1 • Public • Published

microauth-vkontakte 🔐

npm npm npm

CircleCI Codecov Greenkeeper badge

Commitizen friendly PRs Welcome semantic-release All Contributors

styled with prettier nps code style equimper

Vkontakte OAuth for micro.

Running the example

  1. Setup an account with Zeit.
  2. Go to Vkontakte & create an app to get your credentials.
  3. Click the button below and add those credentials along with your Zeit API Token to the environment variables requested by now.
  4. Add the https://your-now-url.now.sh that was generated as the baseURL & authorized redirectURL in your VK Application Dashboard.
  5. Use a browser or a tool like Postman and visit: https://your-now-url.now.sh/auth/vkontakte.

Deploy to now

You may also choose to run the example locally by cloning the repository & following these instructions.

Usage

npm install --save micro microauth-vkontakte
# or 
yarn add micro microauth-vkontakte
const { send } = require('micro')
const microAuthVkontakte = require('microauth-vkontakte')
 
const options = {
  clientId: 'YOUR VK APP ID',
  clientSecret: 'YOUR VK APP SECRET',
  fields: ['city', 'country', 'photo_200'],
  redirectUrl: 'http://localhost:3000/auth/vkontatke/callback',
  scope: ['friends', 'photos']
}
 
const vkontakteAuth = microAuthVkontakte(options)
 
module.exports = vkontakteAuth(async (req, res, auth) => {
  if (!auth) return send(res, 404, 'Not Found')
  if (auth.err) {
    console.log(auth.err)
    return send(res, 403, 'Forbidden')
  }
  return `Hello ${auth.info.first_name}`
})

Default Parameters

The options object you pass to microAuthVkontakte has predefined defaults in place. Should you not provide the 3 required parameters clientId, clientSecret, & redirectUrl you will be informed in your terminal with an error message of what you are missing. The other default parameters as well as documentation for valid values accepted by the Vkontakte API can be found here.

Security

It is your responsibility as a developer to not expose your secure data publicly! Please use such packages as dotenv or dotenv-safe to manage your secure data through environment variables.

Contributing

Please read the CONTRIBUTING.md

Development & Testing

npm test
# or 
yarn test

To verify the package is in working order on your local machine you can run the below script. It will produces ./package. You can then go into the ./example directory and change the location in which microauth-vkontakte is being used:

const microAuthVkontakte = require('../package/src')
npm start package
# or 
yarn start package

License

MIT

Contributors


Cody Brunner

💻 📖 💡 ⚠️

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

Dependencies (4)

Dev Dependencies (15)

Package Sidebar

Install

npm i microauth-vkontakte

Weekly Downloads

9

Version

1.1.1

License

MIT

Unpacked Size

14.5 kB

Total Files

10

Last publish

Collaborators

  • rockchalkwushock