npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

electron-vk-oauth2

v1.0.2

Published

A module which helps to complete vk.com OAuth2 process for standalone apps.

Downloads

10

Readme

electron-vk-oauth2

A module which helps to complete vk.com OAuth2 process for standalone apps.

npm version

Screenshot

Usage

To use this module, install it with npm and require in your electron app. The electron dependency is not supplied with this module, so you have to install it manually.

npm i --save electron-vk-oauth2
const electron = require('electron');
const {app, BrowserWindow} = electron;
const authenticateVK = require('electron-vk-oauth2');

let win;
function createWindow() {
  win = new BrowserWindow({width: 800, height: 600});
  win.loadURL(`file://${__dirname}/index.html`);

  authenticateVK({
      appId: '1234567',
      scope: 'photos',
      revoke: true,
  }, {
      parent: win,
  }).then((res) => {
      console.log('Access token: %s', res.accessToken);
      console.log('User id: %s', res.userId);
      console.log('Expires in: %s', res.expiresIn);
      // now you can make requests to API using access token and pass data to
      // to the renderer process.
  }).catch((err) => {
      // E.g., user denied permissions, or user closed the window without
      // authorising the app.
      console.error(err);
  });
}

app.on('ready', createWindow);

The module exports a function which returns a promise. The promise will be fulfilled once the user has completed authorisation and granted all required permissions. If the user closed the window without authorising the app, the promise will be rejected. If the user denied permissions, or any other error occured, the promise will be rejected.

Options

The first argument is vk specific options:

  • appId: your app id
  • scope: required scope (see access permissions)
  • display [popup]: display type, one of the following: page, popup, mobile
  • revoke: whether to ask users for permissions every time
  • authorizeUrl: https://oauth.vk.com/authorize but you can override it
  • redirectUri: https://oauth.vk.com/blank.html for standalone apps, but the option to override it is available if the API changes in future. Note that all standalone apps are required to use this address, otherwise it's impossible to complete authorisation.

See more info about vk auth flow for standalone apps here.

Window Options

The second argument is options for the window. By default, it will be open with width of 655 and height of 430 and null parent, but you can specify these parameters as properties of the object, or you can pass other options supported by the BrowserWindow:

const authenticateVK = require('electron-vk-oauth2');

authenticateVK({
    appId: 1234567,
    display: page,
}, {
    width: 1024,
    height: 720,
    parent: win, // main application window
    minimizable: false,
    maximizable: false,
    resizable: false,
});

Debug

This package uses debug module. To enable printing debugging information to console, start your app with DEBUG=electron-vk-oauth2 environment variable.

electron-vk-oauth2 open vk auth window https://oauth.vk.com/authorize?state=301&response_type=token&client_id=1234567&scope=photos&display=popup&revoke=1&redirect_uri=https%3A%2F%2Foauth.vk.com%2Fblank.html +13ms
# user logged in
electron-vk-oauth2 Redirect to https://oauth.vk.com/authorize?client_id=5551949&redirect_uri=https%3A%2F%2Foauth.vk.com%2Fblank.html&response_type=token&scope=4&v=&state=301&revoke=1&display=popup&__q_hash=xyz +5s
# user denied permissions
electron-vk-oauth2 Redirect to https://oauth.vk.com/blank.html#error=access_denied&error_reason=user_denied&error_description=User denied your request&state=301 +11s
electron-vk-oauth2 { error: 'access_denied', error_reason: 'user_denied', error_description: 'User denied your request', state: '301' } +1ms
# or user allowed permissions
electron-vk-oauth2 Redirect to https://oauth.vk.com/blank.html#access_token=xyz&expires_in=86400&user_id=123&state=1462 +1s
electron-vk-oauth2 { access_token: 'xyz', expires_in: '86400', user_id: '123', state: '1462' } +1ms