Vk.com login (vkontakte)


(Sam Saffron) #1

Login using vkontakte

Author: @sam

###plugins/vk/plugin.rb

# name: vk.com
# about: Authenticate with discourse with vk.com, see more at: https://vk.com/developers.php?id=-1_37230422&s=1
# version: 0.1.0
# author: Sam Saffron

gem 'omniauth-vkontakte', '1.3.2'


class VkAuthenticator < ::Auth::Authenticator

  CLIENT_ID = '1111111'
  CLIENT_SECRET = 'AUSTRALIASNAKESALAD'

  def name
    'vkontakte'
  end

  def after_authenticate(auth_token)
    result = Auth::Result.new

    # grap the info we need from omni auth
    data = auth_token[:info]
    raw_info = auth_token["extra"]["raw_info"]
    name = data["name"]
    vk_uid = auth_token["uid"]

    # plugin specific data storage
    current_info = ::PluginStore.get("vk", "vk_uid_#{vk_uid}")

    result.user =
      if current_info
        User.where(id: current_info[:user_id]).first
      end

    result.name = name
    result.extra_data = { vk_uid: vk_uid }

    result
  end

  def after_create_account(user, auth)
    data = auth[:extra_data]
    ::PluginStore.set("vk", "vk_uid_#{data[:vk_uid]}", {user_id: user.id })
  end

  def register_middleware(omniauth)
    omniauth.provider :vkontakte,
     CLIENT_ID,
     CLIENT_SECRET
  end
end


auth_provider :title => 'with VKontakte',
    :message => 'Log in via VKontakte (Make sure pop up blockers are not enabled).',
    :frame_width => 920,
    :frame_height => 800,
    :authenticator => VkAuthenticator.new


# We ship with zocial, it may have an icon you like http://zocial.smcllns.com/sample.html
#  in our current case we have an icon for vk
register_css <<CSS

.btn-social.vkontakte {
  background: #46698f;
}

.btn-social.vkontakte:before {
  content: "N";
}

CSS

TODO: move to git
TODO: move settings to site settings


Login with Vk.com Open API
Add a new OAuth2.0 provider
Giving Microsoft some love with omniauth
Official Single-Sign-On for Discourse (sso)
(Илья Лыков) #2

Ruby version: 2.1.1
Authenticator version: 1.3.2

# name: vk.com
# about: Authenticate with discourse with vk.com, see more at: https://vk.com/developers.php?id=-1_37230422&s=1
# version: 0.1.0
# author: Sam Saffron

gem 'omniauth-vkontakte', '1.3.2'

class VkAuthenticator < ::Auth::Authenticator

  CLIENT_ID = 'IDENTIFICATION_SOCIAL'
  CLIENT_SECRET = 'KEY_SOCIAL'

  def name
    'vkontakte'
  end

  def after_authenticate(auth_token)
    result = Auth::Result.new

    # grap the info we need from omni auth
    data = auth_token[:info]
    raw_info = auth_token["extra"]["raw_info"]
    name = data["name"]
    vk_uid = auth_token["uid"]

    # plugin specific data storage
    current_info = ::PluginStore.get("vk", "vk_uid_#{vk_uid}")

    result.user =
      if current_info
        User.where(id: current_info[:user_id]).first
      end

    result.name = name
    result.extra_data = { vk_uid: vk_uid }

    result
  end

  def after_create_account(user, auth)
    data = auth[:extra_data]
    ::PluginStore.set("vk", "vk_uid_#{data[:vk_uid]}", {user_id: user.id })
  end

  def register_middleware(omniauth)
    omniauth.provider :vkontakte,
     CLIENT_ID,
     CLIENT_SECRET
  end
end

auth_provider :title => 'with VKontakte',
    :message => 'Log in via VKontakte (Make sure pop up blockers are not enabled).',
    :frame_width => 920,
    :frame_height => 800,
    :authenticator => VkAuthenticator.new

# We ship with zocial, it may have an icon you like http://zocial.smcllns.com/sample.html
#  in our current case we have an icon for vk
register_css <<CSS

.btn-social.vkontakte {
  background: #46698f;
}

.btn-social.vkontakte:before {
  content: "N";
}

CSS

(Dmitry) #3

Will it ever be compiled as the gem?


(Egor Lyfar) #4

@sam Can you explain how can I install this plugin please?


(Ilya Kuchaev) #5

I’ve created the plugin’s repository: GitHub - Ilya-Kuchaev/discourse-vk-login: VK.com login for Discourse


(Erlend Sogge Heggen) #6

If @kuchaev_iv intends on keeping the plugin up to date, you might as well update topic with a link to his repo, since his version is more up to date than yours (points to the latest version of omniauth-vkontakte).

Also, @dmitry_fedyuk, please just make pull requests to the default repository instead of keeping your own fork, - discourse-forum/vk.com - with nothing but the author attribution altered. That’s not good open source etiquette.


(Олексей же) #7

After plugin install there is no Vk icon:
https://imgur.com/q8HDVoA
How i can solve it?


(Метеор ИТ) #8

Have resolved small bug with icon - GitHub - fao87/discourse-vk-login: VK.com login for Discourse


(Anton) #9

Sam, we’re another forum interested in the official plugin. Are you planning to add it to the official git repo soon?


(Dmitry Krasnoperov) #10

One more vote for VK plugin


(stereobooster) #11

Another one version GitHub - stereobooster/discourse-vk-login: 🚨 [deprecated] VK.com login for Discourse with some improvements: requesting email from vk, add share button


(Sam Saffron) #12

Would you like to take over this plugin? I made the OP wiki, feel free to edit in your github link and add screenshots for share button.


(stereobooster) #13

I want to stabilize/test code before it will become default. I implemented
code which almost the same as Facebooks code. Do you think this is good
idea to add VkontakteUserInfo model?


(Sam Saffron) #14

Yes, but a bit tricky to introduce via a plugin


(stereobooster) #15

Managed to add model. But can’t add custom sharing source. Plugin settings not filtered, even I can see settings button in plugin section. Still fighting


(Dmitry Krasnoperov) #17

How to install it?
Please help!


(Joshua Rosenfeld) #18

Check out @techAPJ’s #howto:


(Dmitry Krasnoperov) #19

Which is the latest and approved version?




#20

(Alex S) #21

I create a plugin based on GitHub - stereobooster/discourse-vk-login: 🚨 [deprecated] VK.com login for Discourse and have it installed. What’s strange is it has some unrelated fields(marked in red), see attachment. Anyone know why?