oa-vkontakte 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +1 -1
- data/README.rdoc +19 -8
- data/VERSION +1 -1
- data/lib/omniauth/strategies/vkontakte_open_api/view_helper.rb +56 -39
- data/oa-vkontakte.gemspec +2 -2
- data/spec/oa-vkontakte_spec.rb +0 -3
- data/spec/spec_helper.rb +1 -0
- metadata +4 -4
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
gem install oa-vkontakte
|
|
8
8
|
|
|
9
|
-
Добавить в config/initializers/
|
|
9
|
+
Добавить в config/initializers/omniauth.rb:
|
|
10
10
|
|
|
11
11
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
|
12
12
|
provider :vkontakte_open_api, <ID приложения>
|
|
@@ -20,16 +20,27 @@
|
|
|
20
20
|
|
|
21
21
|
<%= vkontakte_login_button %>
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
Также кнопка доступна по адресу /auth/vkontakte. Можно пропробовать встроить её как iframe.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
После клика на кнопку и разрешения добавления приложения, будет совершен ajax-запрос на /auth/vkontakte/callback.
|
|
25
|
+
После клика на кнопку и разрешения добавления приложения, будет совершен POST-запрос на /auth/vkontakte/callback.
|
|
28
26
|
В action, к которому будет привязан этот путь, будет доступна переменная
|
|
29
27
|
|
|
30
|
-
request["omniauth.auth"]
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
request["omniauth.auth"]
|
|
29
|
+
|
|
30
|
+
Содержание этой переменной примерно следующее:
|
|
31
|
+
|
|
32
|
+
{
|
|
33
|
+
'uid' => '1234567890', # ID пользователя vkontakte.ru
|
|
34
|
+
'provider' => 'vkontakte',
|
|
35
|
+
'user_info' => {
|
|
36
|
+
'name' => 'Nick Recobra',
|
|
37
|
+
'nickname' => 'oruen',
|
|
38
|
+
'firstName' => 'Nick',
|
|
39
|
+
'lastName' => 'Recobra',
|
|
40
|
+
'image' => 'http://cs191.vkontakte.ru/u00001/e_375bc433.jpg', # путь до вконтактовского аватара
|
|
41
|
+
'urls' => { 'Page' => 'http://vkontakte.ru/id1234567890' }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
33
44
|
|
|
34
45
|
== Ссылки
|
|
35
46
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.2
|
|
@@ -16,7 +16,6 @@ module OmniAuth
|
|
|
16
16
|
<head>
|
|
17
17
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
18
18
|
<title>Вход во ВКонтакте</title>
|
|
19
|
-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
|
|
20
19
|
</head>
|
|
21
20
|
<body>
|
|
22
21
|
HEADER
|
|
@@ -27,64 +26,82 @@ HEADER
|
|
|
27
26
|
<div id="vk_api_transport"></div>
|
|
28
27
|
<script type="text/javascript">
|
|
29
28
|
window.vkAsyncInit = function() {
|
|
30
|
-
/*VK.Observer.subscribe('auth.login', function(response) {
|
|
31
|
-
window.location = '/omniauth/vkontakte/callback';
|
|
32
|
-
});*/
|
|
33
29
|
VK.init({
|
|
34
|
-
apiId: #{OmniAuth.config.vkontakte_app_id},
|
|
30
|
+
apiId: '#{OmniAuth.config.vkontakte_app_id}',
|
|
35
31
|
nameTransportPath: "/xd_receiver.html"
|
|
36
32
|
});
|
|
37
33
|
VK.UI.button('vk_login');
|
|
38
34
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
vkLogin = {
|
|
36
|
+
doLogin: function() {
|
|
37
|
+
VK.Auth.login(vkLogin.loginResult);
|
|
38
|
+
},
|
|
39
|
+
redirectWithPost: function(url, data) {
|
|
40
|
+
method = "POST";
|
|
41
|
+
data = data || {};
|
|
42
|
+
var form = document.createElement("form"),
|
|
43
|
+
input;
|
|
44
|
+
form.setAttribute("action", url);
|
|
45
|
+
form.setAttribute("method", "POST");
|
|
46
|
+
|
|
47
|
+
for (var property in data) {
|
|
48
|
+
if (data.hasOwnProperty(property)) {
|
|
49
|
+
var value = data[property];
|
|
50
|
+
if (value instanceof Array) {
|
|
51
|
+
for (var i = 0, l = value.length; i < l; i++) {
|
|
52
|
+
input = document.createElement("input");
|
|
53
|
+
input.setAttribute("type", "hidden");
|
|
54
|
+
input.setAttribute("name", property);
|
|
55
|
+
input.setAttribute("value", value[i]);
|
|
56
|
+
form.appendChild(input);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
input = document.createElement("input");
|
|
61
|
+
input.setAttribute("type", "hidden");
|
|
62
|
+
input.setAttribute("name", property);
|
|
63
|
+
input.setAttribute("value", value);
|
|
64
|
+
form.appendChild(input);
|
|
53
65
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
document.body.appendChild(form);
|
|
69
|
+
form.submit();
|
|
70
|
+
document.body.removeChild(form);
|
|
71
|
+
},
|
|
72
|
+
loginResult: function (r) {
|
|
73
|
+
if (r.session) {
|
|
74
|
+
if (r.session.expire != "0") {
|
|
75
|
+
vkLogin.getUserProfile(vkLogin.putUserProfile);
|
|
76
|
+
} else if (r.session.expire == "0") {
|
|
77
|
+
VK.Observer.subscribe("auth.sessionChange", function (r) {
|
|
78
|
+
VK.Observer.unsubscribe("auth.sessionChange");
|
|
79
|
+
if (r.session && r.session.expire != "0") {
|
|
80
|
+
vkLogin.getUserProfile(vkLogin.putUserProfile)
|
|
81
|
+
} else {
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
VK.Auth.login()
|
|
85
|
+
}
|
|
56
86
|
}
|
|
57
87
|
},
|
|
58
|
-
|
|
59
|
-
//console.log('called vkGetUserProfile');
|
|
88
|
+
getUserProfile: function (callFunc) {
|
|
60
89
|
var code;
|
|
61
90
|
code = 'return {';
|
|
62
|
-
code += 'me: API.getProfiles({uids: API.getVariable({key: 1280}), fields: "nickname,sex,
|
|
91
|
+
code += 'me: API.getProfiles({uids: API.getVariable({key: 1280}), fields: "nickname,sex,photo"})[0]';
|
|
63
92
|
code += '};';
|
|
64
93
|
VK.Api.call('execute', {
|
|
65
94
|
'code': code
|
|
66
95
|
},
|
|
67
96
|
callFunc);
|
|
68
97
|
},
|
|
69
|
-
|
|
70
|
-
//console.log('called vkPutUserProfile');
|
|
98
|
+
putUserProfile: function (data) {
|
|
71
99
|
if (data.response) {
|
|
72
100
|
r = data.response;
|
|
73
|
-
|
|
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);
|
|
101
|
+
vkLogin.redirectWithPost('#{OmniAuth.config.path_prefix}/vkontakte/callback', r.me);
|
|
82
102
|
}
|
|
83
103
|
}
|
|
84
104
|
};
|
|
85
|
-
window.doLogin = function() {
|
|
86
|
-
VK.Auth.login(LOGINZA.vkLoginResult);
|
|
87
|
-
};
|
|
88
105
|
(function() {
|
|
89
106
|
var el = document.createElement("script");
|
|
90
107
|
el.type = "text/javascript";
|
|
@@ -94,7 +111,7 @@ HEADER
|
|
|
94
111
|
document.getElementById("vk_api_transport").appendChild(el);
|
|
95
112
|
}());
|
|
96
113
|
</script>
|
|
97
|
-
<div id="vk_login" style="margin: 0 auto 20px auto;" onclick="doLogin();"></div>
|
|
114
|
+
<div id="vk_login" style="margin: 0 auto 20px auto;" onclick="vkLogin.doLogin();"></div>
|
|
98
115
|
BUTTON
|
|
99
116
|
end
|
|
100
117
|
|
data/oa-vkontakte.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{oa-vkontakte}
|
|
8
|
-
s.version = "0.1.
|
|
8
|
+
s.version = "0.1.2"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Nick Recobra"]
|
|
12
|
-
s.date = %q{2010-10-
|
|
12
|
+
s.date = %q{2010-10-19}
|
|
13
13
|
s.description = %q{OmniAuth extension for vkontakte.ru authentication}
|
|
14
14
|
s.email = %q{oruenu@gmail.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/oa-vkontakte_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: oa-vkontakte
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 31
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 1
|
|
9
|
-
-
|
|
10
|
-
version: 0.1.
|
|
9
|
+
- 2
|
|
10
|
+
version: 0.1.2
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Nick Recobra
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2010-10-
|
|
18
|
+
date: 2010-10-19 00:00:00 +04:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|