GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - oruen/oa-vkontakte: Расширение OmniAuth и Devise для аутентификации через "ВКонтакте"

BranchesTags
Open more actions menu

Latest commit

 

History

43 Commits
43 Commits

Folders and files

NameName
Last commit message
Last commit date
lib
lib
 
 
spec
spec
 
 
.document
.document
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.rdoc
README.rdoc
 
 
Rakefile
Rakefile
 
 
oa-vkontakte.gemspec
oa-vkontakte.gemspec
 
 

Repository files navigation

oa-vkontakte

OmniAuth с версии 0.2.3 поддерживает (github.com/intridea/omniauth/pull/272) аутентификацию ВКонтакта через OAuth 2.0, предпочтительней использовать его. Этот репозиторий является устаревшим.

Расширение для OmniAuth, реализующее аутентификацию через Vkontate Open Api.

Установка

gem install oa-vkontakte

Добавить в config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :vkontakte, <ID приложения>, <Защищенный ключ приложения>
end

Если ещё не определен, добавить путь в config/routes.rb:

match '/auth/:provider/callback' => 'authentications#create'

В нужную вьюху добавить хелпер, рисующий кнопку входа:

<%= vkontakte_login_button %>

Если хотите свою красивую картинку вместо дефолтной вконтактовской кнопки, делайте так:

<%= vkontakte_login_button(link_to_function( image_tag("/path/to/image"), "vkLogin.doLogin()" )) %>

Также кнопка доступна по адресу /auth/vkontakte, но форма там передается GET-запросом. Можно пропробовать встроить её как iframe.

После клика на кнопку и разрешения добавления приложения, будет совершен POST-запрос на /auth/vkontakte/callback. В action, к которому будет привязан этот путь, будет доступна переменная

request["omniauth.auth"]

Содержание этой переменной примерно следующее:

{
  'uid' => '1234567890', # ID пользователя vkontakte.ru
  'provider' => 'vkontakte',
  'user_info' => {
    'name' => 'Nick Recobra',
    'nickname' => 'oruen',
    'first_name' => 'Nick',
    'last_name' => 'Recobra',
    'image' => 'http://cs191.vkontakte.ru/u00001/e_375bc433.jpg', # путь до вконтактовского аватара
    'urls' => { 'Page' => 'http://vkontakte.ru/id1234567890' } 
  }
}

Интеграция с Devise

Devise с версии 1.2.rc интегрирован с OmniAuth. Подключить к нему oa-vkontakte достаточно просто, дописав в config/initializers/devise.rb:

config.omniauth :vkontakte, <ID приложения>, <Защищенный ключ приложения>

Callback будет приходить действию Devise::OmniauthCallbacks#vkontakte, так что придется озаботиться его наличием. Это удобно сделать, поменяв контроллер для callback’ов OmniAuth в routes.rb:

devise_for :users, :controllers => { :omniauth_callbacks => "authentications" }

AuthenticationsController в этом случае выглядит как-то так:

class AuthenticationsController < Devise::OmniauthCallbacksController
  def vkontakte
    omniauth = request.env["omniauth.auth"]
    # создание или аутентификация пользователя
    ...
  end
end

Ссылки

OmniAuth: github.com/intridea/omniauth

Интеграция OmniAuth и Devise: railscasts.com/episodes/235-omniauth-part-1 и railscasts.com/episodes/236-omniauth-part-2

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010-2011 Nick Recobra. See LICENSE for details.

About

Расширение OmniAuth и Devise для аутентификации через "ВКонтакте"

Resources

Readme
MIT license
Activity

Stars

47 stars

Watchers

1 watching

Forks

7 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.