oa-mailru_alexandrov

Auhtorization with Mail.RU extension for OmniAuth Based on Alexander Gorkunov oa-mailru. Added JQuery magic to Mail.Ru intialization script.

Installation

gem install oa-mailru_alexandrov

Add to environment.rb

config.gem 'oa-mailru_alexandrov', :lib => 'oa-mailru'

Add to config/initializers/omniauth.rb:

#for rails3 projects
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :mail_ru_api, <Application ID>, <Private Key>
end
#for rails2 projects
ActionController::Dispatcher.middleware.use "OmniAuth::Builder" do
  provider :mail_ru_api, <Application ID>, <Private Key>
end

If omniauth routes doesn’t exist add them to config/routes.rb (e.g.):

#rails3
match '/auth/:provider/callback' => 'authentications#create'
#rails2
map.auth_callback '/auth/:provider/callback', :controller => :authentications :action => :create

Then use special helper method for generate mail.ru button:

<%= raw mailru_login_button %>

or if you want use custom button then use:

<%= raw mailru_login_button("<a href='#' onclick='mailruLogin.login();'>Mail.RU Login</a>") %>

After click on the button popup window with mail.ru auth-page will be shown and after user was signed in and added permissions for the application then user-data will be transfered with POST-request to /auth/mailru/callback path. In action with this path you can use params from request which body look like:

{
  'uid' => '1234567890', # user Id from mail.ru
  'provider' => 'mailru',
  'user_info' => {
    'nick' => 'igor.alexandrov',
    'email' => '[email protected]'
    'name' => 'Igor Alexandrov',
    'first_name' => 'Igor',
    'last_name' => 'Alexandrov',
    'picture' => 'userpic url here'
    'country' => 'Russia',
    'town' => 'Tver'
  },
  'extra' => {'user_hash' => 'some additional data here'}
}

Debugging Information

Mail.RU API has some host name permission restrictions, so correct debugging session is available only on public server with some host name (don’t forget to put receiver.html to root directory of your site).

OmniAuth: github.com/intridea/omniauth

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 © 2011 Alexander Gorkunov, Igor Alexandrov. See LICENSE for details.