microauth-vkontakte
v1.1.1
Published
Vkontakte OAuth for micro.
Downloads
6
Maintainers
Readme
microauth-vkontakte :closed_lock_with_key:
Vkontakte OAuth for
micro
.
Running the example
- Setup an account with Zeit.
- Go to Vkontakte & create an app to get your credentials.
- Click the button below and add those credentials along with your Zeit API Token to the environment variables requested by
now
. - Add the
https://your-now-url.now.sh
that was generated as the baseURL & authorized redirectURL in your VK Application Dashboard. - Use a browser or a tool like Postman and visit:
https://your-now-url.now.sh/auth/vkontakte
.
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
Contributors
| Cody Brunner💻 📖 💡 ⚠️ | | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!