oa-vkontakte 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Nick Recobra
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,50 @@
1
+ = oa-vkontakte
2
+
3
+ Расширение для OmniAuth, реализующее аутентификацию через Vkontate Open Api.
4
+
5
+ == Установка
6
+
7
+ gem install oa-vkontakte
8
+
9
+ Добавить в config/initializers/moniauth.rb:
10
+
11
+ Rails.application.config.middleware.use OmniAuth::Builder do
12
+ provider :vkontakte_open_api, <ID приложения>
13
+ end
14
+
15
+ Если ещё не определен, добавить путь в config/routes.rb:
16
+
17
+ match '/auth/:provider/callback' => 'authentications#create'
18
+
19
+ В нужную вьюху добавить хелпер, рисующий кнопку входа:
20
+
21
+ <%= vkontakte_login_button %>
22
+
23
+ Этот хелпер предполагает наличие jQuery на странице для совершения ajax запроса.
24
+
25
+ Также кнопка с подключенной jQuery доступна по адресу /auth/vkontakte. Можно пропробовать встроить её как iframe.
26
+
27
+ После клика на кнопку и разрешения добавления приложения, будет совершен ajax-запрос на /auth/vkontakte/callback.
28
+ В action, к которому будет привязан этот путь, будет доступна переменная request["omniauth.auth"].
29
+ После ajax-запроса страница, на которой находится пользователь, будет перезагружена.
30
+
31
+ == Ссылки
32
+
33
+ OmniAuth: http://github.com/intridea/omniauth
34
+ Интеграция OmniAuth и Devise:
35
+ railscasts.com/episodes/235-omniauth-part-1
36
+ railscasts.com/episodes/236-omniauth-part-2
37
+
38
+ == Note on Patches/Pull Requests
39
+
40
+ * Fork the project.
41
+ * Make your feature addition or bug fix.
42
+ * Add tests for it. This is important so I don't break it in a
43
+ future version unintentionally.
44
+ * Commit, do not mess with rakefile, version, or history.
45
+ (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)
46
+ * Send me a pull request. Bonus points for topic branches.
47
+
48
+ == Copyright
49
+
50
+ Copyright (c) 2010 Nick Recobra. 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-vkontakte"
8
+ gem.summary = %Q{OmniAuth extension for vkontakte.ru authentication}
9
+ gem.description = %Q{OmniAuth extension for vkontakte.ru authentication}
10
+ gem.email = "oruenu@gmail.com"
11
+ gem.homepage = "http://github.com/oruen/oa-vkontakte"
12
+ gem.authors = ["Nick Recobra"]
13
+ gem.rubyforge_project = "oa-vkontakte"
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.1.0
@@ -0,0 +1,4 @@
1
+ require 'omniauth/vkontakte'
2
+ if defined?(Rails)
3
+ ActionController::Base.helper OmniAuth::Strategies::VkontakteOpenApi::ViewHelper::PageHelper
4
+ end
@@ -0,0 +1,43 @@
1
+ require 'omniauth/vkontakte'
2
+ require 'omniauth/strategies/vkontakte_open_api/view_helper'
3
+
4
+ module OmniAuth
5
+ class Configuration
6
+ attr_accessor :vkontakte_app_id
7
+ end
8
+ end
9
+
10
+ module OmniAuth
11
+ module Strategies
12
+ class VkontakteOpenApi
13
+ include OmniAuth::Strategy
14
+ include ViewHelper::PageHelper
15
+
16
+ def initialize(app, app_id, options = {})
17
+ @options = options
18
+ OmniAuth.config.vkontakte_app_id = app_id
19
+ super(app, :vkontakte)
20
+ end
21
+
22
+ attr_reader :app_id
23
+
24
+ def request_phase
25
+ Rack::Response.new(vkontakte_login_page).finish
26
+ end
27
+
28
+ def auth_hash
29
+ OmniAuth::Utils.deep_merge(super(), {
30
+ 'uid' => request[:uid],
31
+ 'user_info' => {
32
+ 'nickname' => request[:nickname],
33
+ 'name' => "#{request[:first_name]} #{request[:last_name]}",
34
+ 'first_name' => request[:first_name],
35
+ 'last_name' => request[:last_name],
36
+ 'image' => request[:photo],
37
+ 'urls' => { 'Page' => 'http://vkontakte.ru/id' + request[:uid] }
38
+ }
39
+ })
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,110 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class VkontakteOpenApi
4
+ class ViewHelper
5
+ module PageHelper
6
+ def vkontakte_login_page
7
+ vkontakte_header +
8
+ vkontakte_login_button +
9
+ vkontakte_footer
10
+ end
11
+
12
+ def vkontakte_header
13
+ <<-HEADER
14
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
15
+ <html xmlns="http://www.w3.org/1999/xhtml">
16
+ <head>
17
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
18
+ <title>Вход во ВКонтакте</title>
19
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
20
+ </head>
21
+ <body>
22
+ HEADER
23
+ end
24
+
25
+ def vkontakte_login_button
26
+ <<-BUTTON
27
+ <div id="vk_api_transport"></div>
28
+ <script type="text/javascript">
29
+ window.vkAsyncInit = function() {
30
+ /*VK.Observer.subscribe('auth.login', function(response) {
31
+ window.location = '/omniauth/vkontakte/callback';
32
+ });*/
33
+ VK.init({
34
+ apiId: #{OmniAuth.config.vkontakte_app_id},
35
+ nameTransportPath: "/xd_receiver.html"
36
+ });
37
+ VK.UI.button('vk_login');
38
+ };
39
+ LOGINZA = {
40
+ vkLoginResult: function (r) {
41
+ //console.log('called vkLoginResult');
42
+ if (r.session && r.session.expire != "0") {
43
+ LOGINZA.vkGetUserProfile(LOGINZA.vkPutUserProfile)
44
+ } else if (r.session.expire == "0") {
45
+ //console.log('VK.bugFix recall login');
46
+ VK.Observer.subscribe("auth.sessionChange", function (r) {
47
+ //console.log('called bugFuxFunc');
48
+ VK.Observer.unsubscribe("auth.sessionChange");
49
+ if (r.session && r.session.expire != "0") {
50
+ LOGINZA.vkGetUserProfile(LOGINZA.vkPutUserProfile)
51
+ } else {
52
+ //console.log("FAILED")
53
+ }
54
+ });
55
+ VK.Auth.login()
56
+ }
57
+ },
58
+ vkGetUserProfile: function (callFunc) {
59
+ //console.log('called vkGetUserProfile');
60
+ var code;
61
+ code = 'return {';
62
+ code += 'me: API.getProfiles({uids: API.getVariable({key: 1280}), fields: "nickname,sex,bdate,city,country,photo,photo_big,has_mobile,rate,home_phone,mobile_phone"})[0]';
63
+ code += '};';
64
+ VK.Api.call('execute', {
65
+ 'code': code
66
+ },
67
+ callFunc);
68
+ },
69
+ vkPutUserProfile: function (data) {
70
+ //console.log('called vkPutUserProfile');
71
+ if (data.response) {
72
+ r = data.response;
73
+ $.ajax({
74
+ type: "POST",
75
+ url: '#{OmniAuth.config.path_prefix}/vkontakte/callback',
76
+ data: r.me,
77
+ success: function () {
78
+ document.location.reload();
79
+ }
80
+ });
81
+ //console.log(data);
82
+ }
83
+ }
84
+ };
85
+ window.doLogin = function() {
86
+ VK.Auth.login(LOGINZA.vkLoginResult);
87
+ };
88
+ (function() {
89
+ var el = document.createElement("script");
90
+ el.type = "text/javascript";
91
+ el.charset = "windows-1251";
92
+ el.src = "http://vkontakte.ru/js/api/openapi.js";
93
+ el.async = true;
94
+ document.getElementById("vk_api_transport").appendChild(el);
95
+ }());
96
+ </script>
97
+ <div id="vk_login" style="margin: 0 auto 20px auto;" onclick="doLogin();"></div>
98
+ BUTTON
99
+ end
100
+
101
+ def vkontakte_footer
102
+ <<-FOOTER
103
+ </body></html>
104
+ FOOTER
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,8 @@
1
+ require 'omniauth/core'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ autoload :VkontakteOpenApi, 'omniauth/strategies/vkontakte_open_api'
6
+ end
7
+ end
8
+
@@ -0,0 +1,65 @@
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-vkontakte}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nick Recobra"]
12
+ s.date = %q{2010-10-14}
13
+ s.description = %q{OmniAuth extension for vkontakte.ru authentication}
14
+ s.email = %q{oruenu@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/oa-vkontakte.rb",
27
+ "lib/omniauth/strategies/vkontakte_open_api.rb",
28
+ "lib/omniauth/strategies/vkontakte_open_api/view_helper.rb",
29
+ "lib/omniauth/vkontakte.rb",
30
+ "oa-vkontakte.gemspec",
31
+ "spec/oa-vkontakte_spec.rb",
32
+ "spec/spec.opts",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/oruen/oa-vkontakte}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubyforge_project = %q{oa-vkontakte}
39
+ s.rubygems_version = %q{1.3.7}
40
+ s.summary = %q{OmniAuth extension for vkontakte.ru authentication}
41
+ s.test_files = [
42
+ "spec/oa-vkontakte_spec.rb",
43
+ "spec/spec_helper.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<oa-core>, ["~> 0.1.4"])
52
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
53
+ s.add_development_dependency(%q<yard>, [">= 0"])
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
+ else
60
+ s.add_dependency(%q<oa-core>, ["~> 0.1.4"])
61
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
62
+ s.add_dependency(%q<yard>, [">= 0"])
63
+ end
64
+ end
65
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "OaVkontakte" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'oa-vkontakte'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oa-vkontakte
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Nick Recobra
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-14 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 vkontakte.ru authentication
68
+ email: oruenu@gmail.com
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - LICENSE
75
+ - README.rdoc
76
+ files:
77
+ - .document
78
+ - .gitignore
79
+ - LICENSE
80
+ - README.rdoc
81
+ - Rakefile
82
+ - VERSION
83
+ - lib/oa-vkontakte.rb
84
+ - lib/omniauth/strategies/vkontakte_open_api.rb
85
+ - lib/omniauth/strategies/vkontakte_open_api/view_helper.rb
86
+ - lib/omniauth/vkontakte.rb
87
+ - oa-vkontakte.gemspec
88
+ - spec/oa-vkontakte_spec.rb
89
+ - spec/spec.opts
90
+ - spec/spec_helper.rb
91
+ has_rdoc: true
92
+ homepage: http://github.com/oruen/oa-vkontakte
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --charset=UTF-8
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project: oa-vkontakte
121
+ rubygems_version: 1.3.7
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: OmniAuth extension for vkontakte.ru authentication
125
+ test_files:
126
+ - spec/oa-vkontakte_spec.rb
127
+ - spec/spec_helper.rb