Unofficial VKontakte strategy for OmniAuth
Switch branches/tags
Nothing to show
Clone or download
Latest commit eb9846e Nov 6, 2017

OmniAuth VKontakte

Build Status Gem Version Code Climate Dependency Status

This is the unofficial OmniAuth strategy for authenticating to VKontakte via OAuth. To use it, you'll need to sign up for an OAuth2 Application ID and Secret on the Vkontakte Developers Page.


Add to your Gemfile:

gem 'omniauth-vkontakte'

Then bundle install


OmniAuth::Strategies::Vkontakte is simply a Rack middleware.

Here's a quick example, adding the middleware to a Rails app in config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :vkontakte, ENV['API_KEY'], ENV['API_SECRET']

See the example Sinatra app.


You can configure several options, which you pass in to the provider method via a Hash:

  • scope: a comma-separated list of access permissions you want to request from the user. Read the Vkontakte docs for more details
  • display: the display context to show the authentication page. Valid options include page, popup and mobile.
  • lang: specifies the language. Optional options include ru, ua, be, en, es, fi, de, it.
  • image_size: defines the size of the user's image. Valid options include mini(50x50), bigger(100x100), bigger_x2(200x200), original(200x*) and original_x2(400x*). Default is mini.
  • info_fields: specify which fields should be added to AuthHash when getting the user's info. Value should be a comma-separated string as per
  • redirect_url: URL where code will be passed. This URL shall be a part of the domain specified in application settings
  • https: 1 - allows you to receive https links to photos and other media. 0 - return an http links (the default).

Here's an example of a possible configuration:

use OmniAuth::Builder do
  provider :vkontakte, ENV['API_KEY'], ENV['API_SECRET'],
      :scope => 'friends,audio,photos',
      :display => 'popup',
      :lang => 'en',
      :https => 1,
      :image_size => 'original'

Authentication Hash

Here's an example Auth Hash available in request.env['omniauth.auth']:

  {"name"=>"Павел Дуров",
   "location"=>"Росiя, Санкт-Петербург",
     "city"=>{"id"=>2, "title"=>"Санкт-Петербург"},
     "country"=>{"id"=>1, "title"=>"Росiя"},

The precise information available may depend on the permissions which you request.

Supported Rubies

Tested with the following Ruby versions:

  • Ruby MRI (1.9.3+)
  • JRuby (1.9 mode)

Contributing to omniauth-vkontakte

  • Fork, fix, then send me a pull request.


Copyright: 2011-2017 Anton Maminov (

This library is distributed under the MIT license. Please see the LICENSE file.