omniauth-vkontakte 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82e2d058974ed802c866153a8248be53642069cc
4
+ data.tar.gz: 9f4b0fdc8a55fe501046821b0b91072028b14cbf
5
+ SHA512:
6
+ metadata.gz: d513abcb0d1ddcff85a9ca4fbcf6108fddc560d414c5c85fe4a8f7cc192bd852850ce43c1852ee25038e9e0abbc889753cdf0cbffba6c5800971cced60cb9d01
7
+ data.tar.gz: 58492ea8f0a56bf9b1d324b5be67942b8d9e973c34a50075ca974c67517a67ab38a0af2c4de23bb7fdd406875ef2cbe576ed59b6b986398518f0e55a74d5d17b
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This is the unofficial [OmniAuth](https://github.com/intridea/omniauth) strategy for authenticating to VKontakte via OAuth.
4
4
  To use it, you'll need to sign up for an OAuth2 Application ID and Secret
5
- on the [Vkontakte Developers Page](http://vk.com/developers.php).
5
+ on the [Vkontakte Developers Page](http://vk.com/dev).
6
6
 
7
7
  ## Basic Usage
8
8
 
@@ -15,24 +15,66 @@ end
15
15
  ## Configuring
16
16
  You can configure several options, which you pass in to the `provider` method via a `Hash`:
17
17
 
18
- * `scope`: A comma-separated list of permissions you want to request from the user. [Read the Vkontakte docs for more details](http://vk.com/developers.php?oid=-1&p=%D0%9F%D1%80%D0%B0%D0%B2%D0%B0_%D0%B4%D0%BE%D1%81%D1%82%D1%83%D0%BF%D0%B0_%D0%BF%D1%80%D0%B8%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D0%B9)
19
- * `display`: The display context to show the authentication page. Options are: `page`, `popup`, `touch` and `wap`.
18
+ * `scope`: a comma-separated list of access permissions you want to request from the user. [Read the Vkontakte docs for more details](http://vk.com/dev/permissions)
19
+ * `display`: the display context to show the authentication page. Options are: `page`, `popup` and `mobile`.
20
+ * `lang`: specifies the language. Optional options are: `ru`, `ua`, `be`, `en`, `es`, `fi`, `de`, `it`.
20
21
 
21
22
  For example, to request `friends`, `audio` and `photos` permissions and display the authentication page in a popup window:
22
23
 
23
24
  ```ruby
24
25
  use OmniAuth::Builder do
25
26
  provider :vkontakte, ENV['API_KEY'], ENV['API_SECRET'],
26
- :scope => 'friends,audio,photos', :display => 'popup'
27
+ :scope => 'friends,audio,photos', :display => 'popup', :lang => 'en'
27
28
  end
28
29
  ```
29
30
 
31
+ ## Auth Hash
32
+
33
+ Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:
34
+
35
+ ```ruby
36
+ {"provider"=>"vkontakte",
37
+ "uid"=>"1",
38
+ "info"=>
39
+ {"name"=>"Павел Дуров",
40
+ "nickname"=>"",
41
+ "first_name"=>"Павел",
42
+ "last_name"=>"Дуров",
43
+ "image"=>"http://cs7001.vk.me/c7003/v7003079/374b/53lwetwOxD8.jpg",
44
+ "location"=>"Росiя, Санкт-Петербург",
45
+ "urls"=>{"Vkontakte"=>"http://vk.com/durov"}},
46
+ "credentials"=>
47
+ {"token"=>
48
+ "187041a618229fdaf16613e96e1caabc1e86e46bbfad228de41520e63fe45873684c365a14417289599f3",
49
+ "expires_at"=>1381826003,
50
+ "expires"=>true},
51
+ "extra"=>
52
+ {"raw_info"=>
53
+ {"id"=>1,
54
+ "first_name"=>"Павел",
55
+ "last_name"=>"Дуров",
56
+ "sex"=>2,
57
+ "nickname"=>"",
58
+ "screen_name"=>"durov",
59
+ "bdate"=>"10.10.1984",
60
+ "city"=>"2",
61
+ "country"=>"1",
62
+ "photo"=>"http://cs7001.vk.me/c7003/v7003079/374b/53lwetwOxD8.jpg",
63
+ "photo_big"=>"http://cs7001.vk.me/c7003/v7003736/3a08/mEqSflTauxA.jpg",
64
+ "online"=>1,
65
+ "online_app"=>"3140623",
66
+ "online_mobile"=>1}}}
67
+ ```
68
+
69
+ The precise information available may depend on the permissions which you request.
70
+
71
+
30
72
  ## Supported Rubies
31
73
 
32
74
  Tested with the following Ruby versions:
33
75
 
76
+ - MRI 2.0.0
34
77
  - MRI 1.9.3
35
- - MRI 1.8.7
36
78
 
37
79
  ## Contributing to omniauth-vkontakte
38
80
 
@@ -40,7 +82,7 @@ Tested with the following Ruby versions:
40
82
 
41
83
  ## License
42
84
 
43
- Copyright (c) 2011, 2012 Anton Maminov
85
+ Copyright (c) 2011-2013 Anton Maminov
44
86
 
45
87
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
46
88
 
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'sinatra'
4
4
  gem 'omniauth-vkontakte', :path => '../'
@@ -11,7 +11,7 @@ SCOPE = 'friends,audio'
11
11
  use Rack::Session::Cookie
12
12
 
13
13
  use OmniAuth::Builder do
14
- provider :vkontakte, ENV['VKONTAKTE_KEY'], ENV['VKONTAKTE_SECRET'], :scope => SCOPE, :display => 'popup'
14
+ provider :vkontakte, ENV['VKONTAKTE_KEY'], ENV['VKONTAKTE_SECRET'], :scope => SCOPE, :display => 'popup', :lang => 'en'
15
15
  end
16
16
 
17
17
  get '/' do
@@ -24,5 +24,6 @@ end
24
24
 
25
25
  get '/auth/:provider/callback' do
26
26
  content_type 'text/plain'
27
+ pp request.env['omniauth.auth']
27
28
  request.env['omniauth.auth'].info.to_hash.inspect
28
29
  end
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Vkontakte
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -1,38 +1,37 @@
1
1
  require 'omniauth/strategies/oauth2'
2
2
  require 'multi_json'
3
+ require 'pp'
3
4
 
4
5
  module OmniAuth
5
6
  module Strategies
6
7
  # Authenticate to Vkontakte utilizing OAuth 2.0 and retrieve
7
8
  # basic user information.
8
9
  # documentation available here:
9
- # http://vk.com/developers.php?o=-17680044&p=Authorization&s=0
10
+ # http://vk.com/dev/authentication
10
11
  #
11
12
  # @example Basic Usage
12
13
  # use OmniAuth::Strategies::Vkontakte, 'API Key', 'Secret Key'
14
+ #
13
15
  class Vkontakte < OmniAuth::Strategies::OAuth2
16
+ API_VERSION = '5.2'
14
17
  DEFAULT_SCOPE = ''
15
18
 
16
19
  option :name, 'vkontakte'
17
20
 
18
21
  option :client_options, {
19
22
  :site => 'https://api.vk.com/',
20
- :token_url => '/oauth/token',
21
- :authorize_url => '/oauth/authorize'
22
- }
23
-
24
- option :access_token_options, {
25
- :param_name => 'access_token'
23
+ :token_url => 'https://oauth.vk.com/access_token',
24
+ :authorize_url => 'https://oauth.vk.com/authorize',
26
25
  }
27
26
 
28
27
  option :authorize_options, [:scope, :display]
29
28
 
30
- uid { access_token.params['user_id'] }
29
+ uid { raw_info['id'].to_s }
31
30
 
32
31
  # https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
33
32
  info do
34
33
  {
35
- :name => "#{raw_info['first_name']} #{raw_info['last_name']}".strip,
34
+ :name => [raw_info['first_name'], raw_info['last_name']].map(&:strip).reject(&:empty?).join(' '),
36
35
  :nickname => raw_info['nickname'],
37
36
  :first_name => raw_info['first_name'],
38
37
  :last_name => raw_info['last_name'],
@@ -40,34 +39,45 @@ module OmniAuth
40
39
  :location => location,
41
40
  :urls => {
42
41
  'Vkontakte' => "http://vk.com/#{raw_info['screen_name']}"
43
- }
42
+ },
44
43
  }
45
44
  end
46
45
 
47
46
  extra do
48
- { 'raw_info' => raw_info }
47
+ {
48
+ 'raw_info' => raw_info
49
+ }
49
50
  end
50
51
 
51
52
  def raw_info
52
- # http://vk.com/developers.php?o=-17680044&p=Description+of+Fields+of+the+fields+Parameter
53
- fields = ['uid', 'first_name', 'last_name', 'nickname', 'screen_name', 'sex', 'city', 'country', 'online', 'bdate', 'photo', 'photo_big']
54
-
53
+ access_token.options[:mode] = :query
54
+ access_token.options[:param_name] = :access_token
55
55
  @raw_info ||= begin
56
56
  params = {
57
- :uids => uid,
58
- :fields => fields.join(','),
59
- #:access_token => access_token.token,
57
+ :fields => info_options,
58
+ :lang => lang_option,
59
+ :v => API_VERSION,
60
60
  }
61
+
61
62
  result = access_token.get('/method/users.get', :params => params).parsed["response"]
62
- result && result.first ? result.first : nil
63
+ (result && result.first) ? result.first : nil
63
64
  end
64
65
  end
65
66
 
66
- ##
67
+ def info_options
68
+ # http://vk.com/dev/fields
69
+ fields = ['nickname', 'screen_name', 'sex', 'city', 'country', 'online', 'bdate', 'photo', 'photo_big']
70
+ return fields.join(',')
71
+ end
72
+
73
+ def lang_option
74
+ options[:lang] || ''
75
+ end
76
+
67
77
  # You can pass +display+ or +scope+ params to the auth request, if
68
78
  # you need to set them dynamically.
69
79
  #
70
- # /auth/vkontakte?display=popup
80
+ # http://vk.com/dev/oauth_dialog
71
81
  #
72
82
  def authorize_params
73
83
  super.tap do |params|
@@ -75,46 +85,50 @@ module OmniAuth
75
85
  %w[display state scope].each do |v|
76
86
  if request.params[v]
77
87
  params[v.to_sym] = request.params[v]
88
+
78
89
  # to support omniauth-oauth2's auto csrf protection
79
90
  session['omniauth.state'] = params[:state] if v == 'state'
80
91
  end
81
92
  end
93
+
82
94
  params[:scope] ||= DEFAULT_SCOPE
83
95
  end
84
96
  end
85
97
 
86
98
  private
87
99
 
88
- # http://vk.com/developers.php?o=-17680044&p=getCountries
100
+ # http://vk.com/dev/database.getCountriesById
89
101
  def get_country
90
102
  if raw_info['country'] && raw_info['country'] != "0"
91
103
  params = {
92
- :cids => raw_info['country'],
93
- :access_token => access_token.token,
104
+ :country_ids => raw_info['country'],
105
+ :lang => lang_option,
106
+ :v => API_VERSION,
94
107
  }
95
- country = access_token.get('/method/places.getCountryById', :params => params).parsed['response']
96
- country && country.first ? country.first['name'] : ''
108
+ country = access_token.get('/method/database.getCountriesById', :params => params).parsed['response']
109
+ country && country.first ? country.first['title'] : ''
97
110
  else
98
111
  ''
99
112
  end
100
113
  end
101
114
 
102
- # http://vk.com/developers.php?o=-17680044&p=getCities
115
+ # http://vk.com/dev/database.getCitiesById
103
116
  def get_city
104
117
  if raw_info['city'] && raw_info['city'] != "0"
105
118
  params = {
106
- :cids => raw_info['city'],
107
- :access_token => access_token.token,
119
+ :city_ids => raw_info['city'],
120
+ :lang => lang_option,
121
+ :v => API_VERSION,
108
122
  }
109
- city = access_token.get('/method/places.getCityById', :params => params).parsed['response']
110
- city && city.first ? city.first['name'] : ''
123
+ city = access_token.get('/method/database.getCitiesById', :params => params).parsed['response']
124
+ city && city.first ? city.first['title'] : ''
111
125
  else
112
126
  ''
113
127
  end
114
128
  end
115
129
 
116
130
  def location
117
- @location ||= "#{get_country}, #{get_city}"
131
+ @location ||= [get_country, get_city].map(&:strip).reject(&:empty?).join(', ')
118
132
  end
119
133
 
120
134
  end
@@ -1,9 +1,8 @@
1
- # -*- encoding: utf-8 -*-
2
1
  require File.expand_path('../lib/omniauth-vkontakte/version', __FILE__)
3
2
 
4
3
  Gem::Specification.new do |gem|
5
- gem.add_dependency 'omniauth', '~> 1.1.0'
6
- gem.add_dependency 'omniauth-oauth2', '~> 1.0'
4
+ gem.add_dependency 'omniauth', '~> 1.0'
5
+ gem.add_dependency 'omniauth-oauth2', '~> 1.1'
7
6
  gem.add_dependency 'multi_json'
8
7
 
9
8
  gem.authors = ["Anton Maminov"]
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-vkontakte
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
5
- prerelease:
4
+ version: 1.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Anton Maminov
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-17 00:00:00.000000000 Z
11
+ date: 2013-10-14 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: omniauth
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: 1.1.0
19
+ version: '1.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: 1.1.0
26
+ version: '1.0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: omniauth-oauth2
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: '1.0'
33
+ version: '1.1'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: '1.0'
40
+ version: '1.1'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: multi_json
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: Unofficial VKontakte strategy for OmniAuth 1.0
@@ -76,26 +69,25 @@ files:
76
69
  - omniauth-vkontakte.gemspec
77
70
  homepage: https://github.com/mamantoha/omniauth-vkontakte
78
71
  licenses: []
72
+ metadata: {}
79
73
  post_install_message:
80
74
  rdoc_options: []
81
75
  require_paths:
82
76
  - lib
83
77
  required_ruby_version: !ruby/object:Gem::Requirement
84
- none: false
85
78
  requirements:
86
- - - ! '>='
79
+ - - '>='
87
80
  - !ruby/object:Gem::Version
88
81
  version: '0'
89
82
  required_rubygems_version: !ruby/object:Gem::Requirement
90
- none: false
91
83
  requirements:
92
- - - ! '>='
84
+ - - '>='
93
85
  - !ruby/object:Gem::Version
94
86
  version: '0'
95
87
  requirements: []
96
88
  rubyforge_project:
97
- rubygems_version: 1.8.24
89
+ rubygems_version: 2.0.3
98
90
  signing_key:
99
- specification_version: 3
91
+ specification_version: 4
100
92
  summary: Unofficial VKontakte strategy for OmniAuth 1.0
101
93
  test_files: []