micro_vkontakte 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,4 @@
1
+ v0.0.7 updated omniauth
1
2
  v0.0.6 added omniauth
2
3
  v0.0.5 bug fixes
3
4
  v0.0.4 bug fixes
data/Manifest CHANGED
@@ -7,4 +7,6 @@ init.rb
7
7
  lib/micro_vkontakte.rb
8
8
  lib/micro_vkontakte/base.rb
9
9
  lib/micro_vkontakte/session.rb
10
- micro_vkontakte.gemspec
10
+ lib/omniauth/strategies/vkontakte.rb
11
+ lib/omniauth/strategies/vkontakte/view_helper.rb
12
+ lib/omniauth/vkontakte.rb
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('micro_vkontakte', '0.0.6') do |p|
5
+ Echoe.new('micro_vkontakte', '0.0.7') do |p|
6
6
  p.description = "Vkontakte api tools."
7
7
  p.url = "http://github.com/gvalmon/micro_vkontakte"
8
8
  p.author = "Iskander Haziev"
@@ -0,0 +1,130 @@
1
+ # coding: utf-8
2
+ module OmniAuth
3
+ module Strategies
4
+ class Vkontakte
5
+ class ViewHelper
6
+ module PageHelper
7
+ def vkontakte_login_page
8
+ vkontakte_header +
9
+ vkontakte_login_button +
10
+ vkontakte_footer
11
+ end
12
+
13
+ def vkontakte_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>Вход во ВКонтакте</title>
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.init({
31
+ apiId: '#{OmniAuth.config.vkontakte_app_id}',
32
+ nameTransportPath: "/xd_receiver.html"
33
+ });
34
+ VK.UI.button('vk_login');
35
+ };
36
+ vkLogin = {
37
+ doLogin: function() {
38
+ VK.Auth.login(vkLogin.loginResult);
39
+ },
40
+ redirectWithPost: function(url, data) {
41
+ data = data || {};
42
+ #{ respond_to?(:request_forgery_protection_token) && respond_to?(:form_authenticity_token) ?
43
+ "data['#{request_forgery_protection_token}'] = '#{form_authenticity_token}'; var method = 'POST';" :
44
+ "var method = 'GET';" }
45
+ var form = document.createElement("form"),
46
+ input;
47
+ form.setAttribute("action", url);
48
+ form.setAttribute("method", method);
49
+
50
+ for (var property in data) {
51
+ if (data.hasOwnProperty(property)) {
52
+ var value = data[property];
53
+ if (value instanceof Array) {
54
+ for (var i = 0, l = value.length; i < l; i++) {
55
+ input = document.createElement("input");
56
+ input.setAttribute("type", "hidden");
57
+ input.setAttribute("name", property);
58
+ input.setAttribute("value", value[i]);
59
+ form.appendChild(input);
60
+ }
61
+ }
62
+ else {
63
+ input = document.createElement("input");
64
+ input.setAttribute("type", "hidden");
65
+ input.setAttribute("name", property);
66
+ input.setAttribute("value", value);
67
+ form.appendChild(input);
68
+ }
69
+ }
70
+ }
71
+ document.body.appendChild(form);
72
+ form.submit();
73
+ document.body.removeChild(form);
74
+ },
75
+ loginResult: function (r) {
76
+ if (r.session) {
77
+ if (r.session.expire != "0") {
78
+ vkLogin.getUserProfile(vkLogin.putUserProfile);
79
+ } else if (r.session.expire == "0") {
80
+ VK.Observer.subscribe("auth.sessionChange", function (r) {
81
+ VK.Observer.unsubscribe("auth.sessionChange");
82
+ if (r.session && r.session.expire != "0") {
83
+ vkLogin.getUserProfile(vkLogin.putUserProfile)
84
+ } else {
85
+ }
86
+ });
87
+ VK.Auth.login()
88
+ }
89
+ }
90
+ },
91
+ getUserProfile: function (callFunc) {
92
+ var code;
93
+ code = 'return {';
94
+ code += 'me: API.getProfiles({uids: API.getVariable({key: 1280}), fields: "nickname,sex,photo"})[0]';
95
+ code += '};';
96
+ VK.Api.call('execute', {
97
+ 'code': code
98
+ },
99
+ callFunc);
100
+ },
101
+ putUserProfile: function (data) {
102
+ if (data.response) {
103
+ r = data.response;
104
+ vkLogin.redirectWithPost('#{OmniAuth.config.path_prefix}/vkontakte/callback', r.me);
105
+ }
106
+ }
107
+ };
108
+ (function() {
109
+ var el = document.createElement("script");
110
+ el.type = "text/javascript";
111
+ el.charset = "windows-1251";
112
+ el.src = "http://vkontakte.ru/js/api/openapi.js";
113
+ el.async = true;
114
+ document.getElementById("vk_api_transport").appendChild(el);
115
+ }());
116
+ </script>
117
+ <img id="vk_login" src="/images/auth/vk.png" onclick="vkLogin.doLogin();" />
118
+ BUTTON
119
+ end
120
+
121
+ def vkontakte_footer
122
+ <<-FOOTER
123
+ </body></html>
124
+ FOOTER
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,56 @@
1
+ require 'omniauth/vkontakte'
2
+ require 'omniauth/strategies/vkontakte/view_helper'
3
+
4
+ module OmniAuth
5
+ class Configuration
6
+ attr_accessor :vkontakte_app_id
7
+ attr_accessor :vkontakte_app_key
8
+ end
9
+ end
10
+
11
+ module OmniAuth
12
+ module Strategies
13
+ class Vkontakte
14
+ include OmniAuth::Strategy
15
+ include ViewHelper::PageHelper
16
+
17
+ def initialize(app, app_id, app_key, options = {})
18
+ @options = options
19
+ OmniAuth.config.vkontakte_app_id = app_id
20
+ OmniAuth.config.vkontakte_app_key = app_key
21
+ super(app, :vkontakte)
22
+ end
23
+
24
+ attr_reader :app_id
25
+
26
+ def request_phase
27
+ Rack::Response.new(vkontakte_login_page).finish
28
+ end
29
+
30
+ def callback_phase
31
+ app_cookie = request.cookies["vk_app_#{OmniAuth.config.vkontakte_app_id}"]
32
+ return fail!(:invalid_credentials) unless app_cookie
33
+ args = app_cookie.split("&")
34
+ sig_index = args.index { |arg| arg =~ /^sig=/ }
35
+ return fail!(:invalid_credentials) unless sig_index
36
+ sig = args.delete_at(sig_index)
37
+ return fail!(:invalid_credentials) unless Digest::MD5.new.hexdigest(args.sort.join('') + OmniAuth.config.vkontakte_app_key) == sig[4..-1]
38
+ super
39
+ end
40
+
41
+ def auth_hash
42
+ OmniAuth::Utils.deep_merge(super(), {
43
+ 'uid' => request[:uid],
44
+ 'user_info' => {
45
+ 'nickname' => request[:nickname],
46
+ 'name' => "#{request[:first_name]} #{request[:last_name]}",
47
+ 'first_name' => request[:first_name],
48
+ 'last_name' => request[:last_name],
49
+ 'image' => request[:photo],
50
+ 'urls' => { 'Page' => 'http://vkontakte.ru/id' + request[:uid] }
51
+ }
52
+ })
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,8 @@
1
+ require 'omniauth/core'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ autoload :Vkontakte, 'omniauth/strategies/vkontakte'
6
+ end
7
+ end
8
+
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{micro_vkontakte}
5
- s.version = "0.0.6"
5
+ s.version = "0.0.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Iskander Haziev"]
9
9
  s.date = %q{2011-03-06}
10
10
  s.description = %q{Vkontakte api tools.}
11
11
  s.email = %q{gvalmon@gmail.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/micro_vkontakte.rb", "lib/micro_vkontakte/base.rb", "lib/micro_vkontakte/session.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "init.rb", "lib/micro_vkontakte.rb", "lib/micro_vkontakte/base.rb", "lib/micro_vkontakte/session.rb", "micro_vkontakte.gemspec"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/micro_vkontakte.rb", "lib/micro_vkontakte/base.rb", "lib/micro_vkontakte/session.rb", "lib/omniauth/strategies/vkontakte.rb", "lib/omniauth/strategies/vkontakte/view_helper.rb", "lib/omniauth/vkontakte.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "init.rb", "lib/micro_vkontakte.rb", "lib/micro_vkontakte/base.rb", "lib/micro_vkontakte/session.rb", "lib/omniauth/strategies/vkontakte.rb", "lib/omniauth/strategies/vkontakte/view_helper.rb", "lib/omniauth/vkontakte.rb", "micro_vkontakte.gemspec"]
14
14
  s.homepage = %q{http://github.com/gvalmon/micro_vkontakte}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Micro_vkontakte", "--main", "README"]
16
16
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_vkontakte
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Iskander Haziev
@@ -45,6 +45,9 @@ extra_rdoc_files:
45
45
  - lib/micro_vkontakte.rb
46
46
  - lib/micro_vkontakte/base.rb
47
47
  - lib/micro_vkontakte/session.rb
48
+ - lib/omniauth/strategies/vkontakte.rb
49
+ - lib/omniauth/strategies/vkontakte/view_helper.rb
50
+ - lib/omniauth/vkontakte.rb
48
51
  files:
49
52
  - CHANGELOG
50
53
  - LICENSE
@@ -55,6 +58,9 @@ files:
55
58
  - lib/micro_vkontakte.rb
56
59
  - lib/micro_vkontakte/base.rb
57
60
  - lib/micro_vkontakte/session.rb
61
+ - lib/omniauth/strategies/vkontakte.rb
62
+ - lib/omniauth/strategies/vkontakte/view_helper.rb
63
+ - lib/omniauth/vkontakte.rb
58
64
  - micro_vkontakte.gemspec
59
65
  has_rdoc: true
60
66
  homepage: http://github.com/gvalmon/micro_vkontakte