https://rubygems.org/gems/omniauth-vk
Authorization OmniAuth strategy for vk.com. Current api version is 5.45. More details here
Add to your Gemfile
gem 'omniauth-vk'
Then bundle install
You can use RVM environment variables. Read more
Add the middleware to a Rails app in config/initializers/omniauth.rb
:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :vk, ENV['VK_KEY'], ENV['VK_SECRET']
end
or in other rack-based applications
use OmniAuth::Builder do
provider :vk, ENV['VK_KEY'], ENV['VK_SECRET']
end
Add in config/initializers/devise.rb
:
config.omniauth :vk, ENV['VK_KEY'],
ENV['VK_SECRET']
You can use auth params
config.omniauth :vk, ENV['VK_KEY'],
ENV['VK_SECRET'],
redirect_uri: '/auth/vk',
# Available values: page - default, popup, mobile - default for mobile devices
display: 'popup',
# List of Available Settings of Access Permissions https://vk.com/dev/permissions
scope: 'email, friends',
v: 5.42
config.omniauth :vk, ENV['VK_KEY'],
ENV['VK_SECRET'],
# Available values: ru, ua, be, en, es, fi, de, it
lang 'en'
https: 1,
test_mode: 1
{ "provider"=>"vk",
"uid"=>"1",
"info"=> {
"name"=>"Павел Дуров",
"first_name"=>"Павел",
"last_name"=>"Дуров",
"user_id"=>"1"
},
"credentials"=> {
"token"=> "187041a618229fdaf16613e96e1caabc1e86e46bbfad228de41520e63fe45873684c365a14417289599f3",
"expires_at"=>1381826003,
"expires"=>true
},
"extra"=> {
"raw_info"=> {
"id"=>1,
"first_name"=>"Павел",
"last_name"=>"Дуров" }
}
}
List of all available fields here
config.omniauth :vk, ENV['VK_KEY'],
ENV['VK_SECRET'],
scope: 'email' # email doesn't provided by default
fields: 'sex, bdate, city, country'
{ "provider"=>"vk",
"uid"=>"1",
"info"=> {
"email"=>"",
"name"=>"Павел Дуров",
"first_name"=>"Павел",
"last_name"=>"Дуров",
"user_id"=>"1"
},
"credentials"=> {
"token"=> "187041a618229fdaf16613e96e1caabc1e86e46bbfad228de41520e63fe45873684c365a14417289599f3",
"expires_at"=>1381826003,
"expires"=>true
},
"extra"=> {
"raw_info"=> {
"first_name"=>"Павел",
"id"=>1,
"last_name"=>"Дуров"
"sex"=>2,
"bdate"=>"10.10.1984",
"city"=>"2",
"country"=>"1",}
}
}
Bug reports and pull requests are welcome on GitHub at https://github.com/Sharevari-Inc/omniauth-vk. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.