Wondering what’s next for npm?Check out our public roadmap! »

hapi-vkminiapps-auth

1.0.6 • Public • Published

VK Mini Apps auth fo Hapi

Simple implementation for auth flow in VK Mini Apps

Docs

npm install --save hapi-vkminiapps-auth

Usage:

const Hapi = require('@hapi/hapi');
 
const start = async () => {
    const server = Hapi.server({ port: 4000 });
 
    await server.register(require('hapi-vkminiapps-auth'));
 
    server.auth.strategy('vk', 'vk-mini-app', { clientSecret: '...', validate: async (credentials) => { // Credentials is same as below
      if (credentials.vk_user_id === 98712) {
        return {isValid: true, credentials}
      } else {
        return {isValid: false, error: 'Forbidden'}
      }    
    }});
 
    server.route({
        method: 'GET',
        path: '/',
        options: {
            auth: 'vk'
        },
        handler: function (request) {
 
            return request.auth.credentials;
        }
    });
    await server.start();
 
    console.log('server running at: ' + server.info.uri);
};
 
start();

Example request.auth.credentials:

{
    "vk_access_token_settings": "friends",
    "vk_app_id": 7130099,
    "vk_are_notifications_enabled": 0,
    "vk_is_app_user": 0,
    "vk_is_favorite": 0,
    "vk_language": "ru",
    "vk_platform": "desktop_web",
    "vk_ref": "other",
    "vk_user_id": 1234
}

Hint:

If you use nginx add underscores_in_headers on; to your server section.

Install

npm i hapi-vkminiapps-auth

DownloadsWeekly Downloads

1

Version

1.0.6

License

MIT

Unpacked Size

6.06 kB

Total Files

5

Last publish

Collaborators

  • avatar