oa-mailru 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Alexander Gorkunov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,83 @@
1
+ = oa-mailru
2
+
3
+ Auhtorization with Mail.RU extension for OmniAuth
4
+
5
+ == Installation
6
+
7
+ gem install oa-mailru
8
+
9
+ Add to config/initializers/omniauth.rb:
10
+
11
+ #for rails3 projects
12
+ Rails.application.config.middleware.use OmniAuth::Builder do
13
+ provider :mail_ru_api, <Application ID>, <Private Key>
14
+ end
15
+ #for rails2 projects
16
+ ActionController::Dispatcher.middleware.use "OmniAuth::Builder" do
17
+ provider :mail_ru_api, <Application ID>, <Private Key>
18
+ end
19
+
20
+ If omniauth routes doesn't exist add them to config/routes.rb (e.g.):
21
+
22
+ #rails3
23
+ match '/auth/:provider/callback' => 'authentications#create'
24
+ #rails2
25
+ map.auth_callback '/auth/:provider/callback', :controller => :authentications :action => :create
26
+
27
+ Then use special helper method for generate mail.ru button:
28
+
29
+ <%= raw mailru_login_button %>
30
+
31
+ or if you want use custom button then use:
32
+
33
+ <%= raw mailru_login_button("<a href='#' onclick='mailruLogin.login();'>Mail.RU Login</a>") %>
34
+
35
+ or if you want use jquery ajaxForm then use:
36
+
37
+ <%= raw mailru_login_button(nil, true) %>
38
+
39
+ ajaForm with custom button
40
+
41
+ <%= raw mailru_login_button("<a href='#' onclick='mailruLogin.login();'>Mail.RU Login</a>", true) %>
42
+
43
+ After click on the button popup window with mail.ru auth-page will be shown and after user was signed in and added
44
+ permissions for the application then user-data will be transfered with POST-request to /auth/mailru/callback path.
45
+ In action with this path you can use params from request["omniauth.auth"] which body look like:
46
+
47
+ {
48
+ 'uid' => '1234567890', # user Id from mail.ru
49
+ 'provider' => 'mailru',
50
+ 'user_info' => {
51
+ 'nick' => 'alexander.gorkunov',
52
+ 'name' => 'Alexander Gorkunov',
53
+ 'first_name' => 'Alexander',
54
+ 'last_name' => 'Gorkunov',
55
+ 'picture' => 'userpic url here'
56
+ 'country' => 'Russia',
57
+ 'town' => 'Samara'
58
+ },
59
+ 'extra' => {'user_hash' => 'some additional data here'}
60
+ }
61
+
62
+ == Debuging Information
63
+
64
+ Mail.RU API has some host name permission restrictions, so correct debugging session is available only on public server with
65
+ some host name (don't forget to put receiver.html to root directory of your site).
66
+
67
+ == Links
68
+
69
+ OmniAuth: http://github.com/intridea/omniauth
70
+
71
+ == Note on Patches/Pull Requests
72
+
73
+ * Fork the project.
74
+ * Make your feature addition or bug fix.
75
+ * Add tests for it. This is important so I don't break it in a
76
+ future version unintentionally.
77
+ * Commit, do not mess with rakefile, version, or history.
78
+ (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)
79
+ * Send me a pull request. Bonus points for topic branches.
80
+
81
+ == Copyright
82
+
83
+ Copyright (c) 2010 Alexander Gorkunov. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "oa-mailru"
8
+ gem.summary = %Q{OmniAuth extension for mail.ru authentication}
9
+ gem.description = %Q{OmniAuth extension for mail.ru authentication}
10
+ gem.email = "alexander.gorkunov@gmail.com"
11
+ gem.homepage = "http://github.com/gorkunov/oa-mailru"
12
+ gem.authors = ["Alexander Gorkunov"]
13
+ gem.rubyforge_project = "oa-mailru"
14
+ gem.add_dependency 'oa-core', '~>0.1.4'
15
+ gem.add_development_dependency "rspec", ">= 1.2.9"
16
+ gem.add_development_dependency "yard", ">= 0"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ Jeweler::RubyforgeTasks.new do |rubyforge|
21
+ rubyforge.doc_task = "yardoc"
22
+ end
23
+ rescue LoadError
24
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
25
+ end
26
+
27
+ require 'spec/rake/spectask'
28
+ Spec::Rake::SpecTask.new(:spec) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.spec_files = FileList['spec/**/*_spec.rb']
31
+ end
32
+
33
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
34
+ spec.libs << 'lib' << 'spec'
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :spec => :check_dependencies
40
+
41
+ task :default => :spec
42
+
43
+ begin
44
+ require 'yard'
45
+ YARD::Rake::YardocTask.new
46
+ rescue LoadError
47
+ task :yardoc do
48
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
49
+ end
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/oa-mailru.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'omniauth/mailru'
2
+ if defined?(Rails)
3
+ ActionController::Base.helper OmniAuth::Strategies::MailRuApi::ViewHelper::PageHelper
4
+ end
@@ -0,0 +1,8 @@
1
+ require 'omniauth/core'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ autoload :MailRuApi, 'omniauth/strategies/mailru_api'
6
+ end
7
+ end
8
+
@@ -0,0 +1,128 @@
1
+ # coding: utf-8
2
+ module OmniAuth
3
+ module Strategies
4
+ class MailRuApi
5
+ class ViewHelper
6
+ module PageHelper
7
+ def mailru_login_page
8
+ mailru_header +
9
+ mailru_login_button +
10
+ mailru_footer
11
+ end
12
+
13
+ def mailru_header
14
+ <<-HEADER
15
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
16
+ <html xmlns="http://www.w3.org/1999/xhtml">
17
+ <head>
18
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
19
+ <title>Вход в Mail.RU</title>
20
+ </head>
21
+ <body>
22
+ HEADER
23
+ end
24
+
25
+ def mailru_login_button(control = nil, use_jquery_form = false)
26
+ unless control.present?
27
+ control = "<a class='mrc__connectButton'></a>"
28
+ init_control = "mailru.connect.initButton();"
29
+ end
30
+ <<-BUTTON
31
+ <div id="mailru_api_transport" style="display:inline;"></div>
32
+ <script type="text/javascript">
33
+ mailruLogin = {
34
+ initialized: false,
35
+ initMailRuApi: function() {
36
+ mailru.connect.init('#{OmniAuth.config.mailru_app_id}', '#{OmniAuth.config.mailru_private_key}');
37
+ #{init_control}
38
+ mailru.events.listen(mailru.connect.events.login, function(session){
39
+ mailru.common.users.getInfo(function(result){
40
+ mailruLogin.redirectWithPost('#{OmniAuth.config.path_prefix}/mailru/callback', result[0]);
41
+ });
42
+ });
43
+ mailruLogin.initialized = true;
44
+ },
45
+ onLoad: function() {
46
+ mailru.loader.require('api', function() {
47
+ mailruLogin.initMailRuApi();
48
+ });
49
+ },
50
+ login: function(){
51
+ if(!mailruLogin.initialized) mailruLogin.initMailRuApi();
52
+ mailru.connect.login();
53
+ },
54
+ redirectWithPost: function(url, data) {
55
+ data = data || {};
56
+ #{ respond_to?(:request_forgery_protection_token) && respond_to?(:form_authenticity_token) ?
57
+ "data['#{request_forgery_protection_token}'] = '#{form_authenticity_token}'; var method = 'POST';" :
58
+ "var method = 'GET';" }
59
+ var form = document.createElement("form"),
60
+ input;
61
+ form.setAttribute("action", url);
62
+ form.setAttribute("method", method);
63
+
64
+ for (var property in data) {
65
+ if (data.hasOwnProperty(property)) {
66
+ var value = data[property];
67
+ if(property == 'location') {
68
+ input = document.createElement("input");
69
+ input.setAttribute("type", "hidden");
70
+ input.setAttribute("name", 'county');
71
+ input.setAttribute("value", value['country']['name']);
72
+ form.appendChild(input);
73
+ input = document.createElement("input");
74
+ input.setAttribute("type", "hidden");
75
+ input.setAttribute("name", 'city');
76
+ input.setAttribute("value", value['city']['name']);
77
+ form.appendChild(input);
78
+ }
79
+ else if (value instanceof Array) {
80
+ for (var i = 0, l = value.length; i < l; i++) {
81
+ input = document.createElement("input");
82
+ input.setAttribute("type", "hidden");
83
+ input.setAttribute("name", property);
84
+ input.setAttribute("value", value[i]);
85
+ form.appendChild(input);
86
+ }
87
+ }
88
+ else {
89
+ input = document.createElement("input");
90
+ input.setAttribute("type", "hidden");
91
+ input.setAttribute("name", property);
92
+ input.setAttribute("value", value);
93
+ form.appendChild(input);
94
+ }
95
+ }
96
+ }
97
+ document.body.appendChild(form);
98
+ #{ user_ajax ? "$(form).ajaxSubmit({ dataType: 'script' });" : "form.submit();" }
99
+ document.body.removeChild(form);
100
+ }
101
+ };
102
+ (function() {
103
+ var el = document.createElement("script");
104
+ el.type = "text/javascript";
105
+ el.charset = "windows-1251";
106
+ el.src = "http://cdn.connect.mail.ru/js/loader.js";
107
+ el.async = true;
108
+ el.onreadystatechange= function () {
109
+ if (this.readyState == 'complete') mailruLogin.onLoad();
110
+ }
111
+ el.onload= mailruLogin.onLoad;
112
+ document.getElementById("mailru_api_transport").appendChild(el);
113
+ }());
114
+ </script>
115
+ #{control}
116
+ BUTTON
117
+ end
118
+
119
+ def mailru_footer
120
+ <<-FOOTER
121
+ </body></html>
122
+ FOOTER
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,48 @@
1
+ require 'omniauth/mailru'
2
+ require 'omniauth/strategies/mailru_api/view_helper'
3
+
4
+ module OmniAuth
5
+ class Configuration
6
+ attr_accessor :mailru_app_id, :mailru_private_key
7
+ end
8
+ end
9
+
10
+ module OmniAuth
11
+ module Strategies
12
+ class MailRuApi
13
+ include OmniAuth::Strategy
14
+ include ViewHelper::PageHelper
15
+
16
+ def initialize(app, app_id, app_private_key, options = {})
17
+ OmniAuth.config.mailru_app_id = app_id
18
+ OmniAuth.config.mailru_private_key = app_private_key
19
+ @options = options
20
+ super(app, :mailru)
21
+ end
22
+
23
+ attr_reader :app_id
24
+ attr_reader :app_private_key
25
+
26
+ def request_phase
27
+ Rack::Response.new(mailru_login_page).finish
28
+ end
29
+
30
+ def auth_hash
31
+ OmniAuth::Utils.deep_merge(super(), {
32
+ 'uid' => request[:uid],
33
+ 'user_info' => {
34
+ 'nick' => request[:nick],
35
+ 'name' => "#{request[:first_name]} #{request[:last_name]}",
36
+ 'first_name' => request[:first_name],
37
+ 'last_name' => request[:last_name],
38
+ 'picture' => request[:has_pic] ? request[:pic] : nil,
39
+ 'country' => request[:country],
40
+ 'town' => request[:city],
41
+ 'urls' => { 'Page' => request[:link] }
42
+ },
43
+ 'extra' => {'user_hash' => request}
44
+ })
45
+ end
46
+ end
47
+ end
48
+ end
data/oa-mailru.gemspec ADDED
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{oa-mailru}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alexander Gorkunov"]
12
+ s.date = %q{2010-10-29}
13
+ s.description = %q{OmniAuth extension for mail.ru authentication}
14
+ s.email = %q{alexander.gorkunov@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "lib/oa-mailru.rb",
25
+ "lib/omniauth/mailru.rb",
26
+ "lib/omniauth/strategies/mailru_api.rb",
27
+ "lib/omniauth/strategies/mailru_api/view_helper.rb",
28
+ "oa-mailru.gemspec"
29
+ ]
30
+ s.homepage = %q{http://github.com/gorkunov/oa-mailru}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubyforge_project = %q{oa-mailru}
34
+ s.rubygems_version = %q{1.3.7}
35
+ s.summary = %q{OmniAuth extension for mail.ru authentication}
36
+ s.test_files = [
37
+ "spec/spec_helper.rb",
38
+ "spec/oa-mailru_spec.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<oa-core>, ["~> 0.1.4"])
47
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
48
+ s.add_development_dependency(%q<yard>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<oa-core>, ["~> 0.1.4"])
51
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
52
+ s.add_dependency(%q<yard>, [">= 0"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<oa-core>, ["~> 0.1.4"])
56
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
57
+ s.add_dependency(%q<yard>, [">= 0"])
58
+ end
59
+ end
60
+
@@ -0,0 +1,4 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "OaMailRu" do
4
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
4
+ require 'oa-mailru'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oa-mailru
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Alexander Gorkunov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-29 00:00:00 +04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: oa-core
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 4
34
+ version: 0.1.4
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 13
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 9
50
+ version: 1.2.9
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: yard
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
67
+ description: OmniAuth extension for mail.ru authentication
68
+ email: alexander.gorkunov@gmail.com
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - LICENSE
75
+ - README.rdoc
76
+ files:
77
+ - LICENSE
78
+ - README.rdoc
79
+ - Rakefile
80
+ - VERSION
81
+ - lib/oa-mailru.rb
82
+ - lib/omniauth/mailru.rb
83
+ - lib/omniauth/strategies/mailru_api.rb
84
+ - lib/omniauth/strategies/mailru_api/view_helper.rb
85
+ - oa-mailru.gemspec
86
+ - spec/spec_helper.rb
87
+ - spec/oa-mailru_spec.rb
88
+ has_rdoc: true
89
+ homepage: http://github.com/gorkunov/oa-mailru
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options:
94
+ - --charset=UTF-8
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ requirements: []
116
+
117
+ rubyforge_project: oa-mailru
118
+ rubygems_version: 1.3.7
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: OmniAuth extension for mail.ru authentication
122
+ test_files:
123
+ - spec/spec_helper.rb
124
+ - spec/oa-mailru_spec.rb