oa-vkontakte_alexandrov 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,48 +1,103 @@
1
+ # require 'rubygems'
2
+ # require 'rake'
3
+ #
4
+ # begin
5
+ # require 'jeweler'
6
+ # Jeweler::Tasks.new do |gem|
7
+ # # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
8
+ # gem.name = "oa-vkontakte_alexandrov"
9
+ # gem.homepage = "http://github.com/igor-alexandrov/oa-vkontakte"
10
+ # gem.license = "MIT"
11
+ # gem.summary = %Q{VKontakte OmniAuth module with view helpers}
12
+ # gem.description = %Q{Include this gem into your project with OmniAuth gem and you will get VKontakte login in one line of code.}
13
+ # gem.email = "igor.alexandrov@gmail.com"
14
+ # gem.authors = ["Igor Alexandrov"]
15
+ # gem.add_dependency 'oa-core', '>= 0.2.0.beta4'
16
+ # gem.add_development_dependency "rspec", ">= 1.2.9"
17
+ # gem.add_development_dependency "yard", ">= 0"
18
+ # end
19
+ # Jeweler::RubygemsDotOrgTasks.new
20
+ # rescue LoadError
21
+ # puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ # end
23
+ #
24
+ #
25
+ # require 'spec/rake/spectask'
26
+ # Spec::Rake::SpecTask.new(:spec) do |spec|
27
+ # spec.libs << 'lib' << 'spec'
28
+ # spec.spec_files = FileList['spec/**/*_spec.rb']
29
+ # end
30
+ #
31
+ # Spec::Rake::SpecTask.new(:rcov) do |spec|
32
+ # spec.libs << 'lib' << 'spec'
33
+ # spec.pattern = 'spec/**/*_spec.rb'
34
+ # spec.rcov = true
35
+ # end
36
+ #
37
+ # task :spec => :check_dependencies
38
+ #
39
+ # task :default => :spec
40
+ #
41
+ # begin
42
+ # require 'yard'
43
+ # YARD::Rake::YardocTask.new
44
+ # rescue LoadError
45
+ # task :yardoc do
46
+ # abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
47
+ # end
48
+ # end
49
+
50
+
51
+
1
52
  require 'rubygems'
53
+ require 'bundler'
54
+ begin
55
+ Bundler.setup(:default, :development)
56
+ rescue Bundler::BundlerError => e
57
+ $stderr.puts e.message
58
+ $stderr.puts "Run `bundle install` to install missing gems"
59
+ exit e.status_code
60
+ end
2
61
  require 'rake'
3
62
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
8
- gem.name = "oa-vkontakte_alexandrov"
9
- gem.homepage = "http://github.com/igor-alexandrov/oa-vkontakte"
10
- gem.license = "MIT"
11
- gem.summary = %Q{VKontakte OmniAuth module with view helpers}
12
- gem.description = %Q{Include this gem into your project with OmniAuth gem and you will get VKontakte login in one line of code.}
13
- gem.email = "igor.alexandrov@gmail.com"
14
- gem.authors = ["Igor Alexandrov"]
15
- gem.add_dependency 'oa-core', '~>0.1.4'
16
- gem.add_development_dependency "rspec", ">= 1.2.9"
17
- gem.add_development_dependency "yard", ">= 0"
18
- end
19
- Jeweler::RubygemsDotOrgTasks.new
20
- rescue LoadError
21
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
63
+ require 'jeweler'
64
+ Jeweler::Tasks.new do |gem|
65
+ gem.name = "oa-vkontakte_alexandrov"
66
+ gem.homepage = "http://github.com/igor-alexandrov/oa-vkontakte"
67
+ gem.license = "MIT"
68
+ gem.summary = %Q{VKontakte OmniAuth module with view helpers}
69
+ gem.description = %Q{Include this gem into your project with OmniAuth gem and you will get VKontakte login in one line of code.}
70
+ gem.email = "igor.alexandrov@gmail.com"
71
+ gem.authors = ["Igor Alexandrov"]
72
+ gem.add_dependency 'oa-core', '>= 0.2.0.beta4'
73
+ gem.add_development_dependency "rspec", ">= 1.2.9"
74
+ gem.add_development_dependency "yard", ">= 0"
22
75
  end
23
-
76
+ Jeweler::RubygemsDotOrgTasks.new
24
77
 
25
- require 'spec/rake/spectask'
26
- Spec::Rake::SpecTask.new(:spec) do |spec|
27
- spec.libs << 'lib' << 'spec'
28
- spec.spec_files = FileList['spec/**/*_spec.rb']
78
+ require 'rake/testtask'
79
+ Rake::TestTask.new(:test) do |test|
80
+ test.libs << 'lib' << 'test'
81
+ test.pattern = 'test/**/test_*.rb'
82
+ test.verbose = true
29
83
  end
30
84
 
31
- Spec::Rake::SpecTask.new(:rcov) do |spec|
32
- spec.libs << 'lib' << 'spec'
33
- spec.pattern = 'spec/**/*_spec.rb'
34
- spec.rcov = true
85
+ require 'rcov/rcovtask'
86
+ Rcov::RcovTask.new do |test|
87
+ test.libs << 'test'
88
+ test.pattern = 'test/**/test_*.rb'
89
+ test.verbose = true
90
+ test.rcov_opts << '--exclude "gems/*"'
35
91
  end
36
92
 
37
- task :spec => :check_dependencies
93
+ task :default => :test
38
94
 
39
- task :default => :spec
95
+ require 'rake/rdoctask'
96
+ Rake::RDocTask.new do |rdoc|
97
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
98
 
41
- begin
42
- require 'yard'
43
- YARD::Rake::YardocTask.new
44
- rescue LoadError
45
- task :yardoc do
46
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
47
- end
99
+ rdoc.rdoc_dir = 'rdoc'
100
+ rdoc.title = "oa-vkontakte_alexandrov #{version}"
101
+ rdoc.rdoc_files.include('README*')
102
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
103
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,44 +1,95 @@
1
+ require 'omniauth/strategies/oauth'
2
+
1
3
  require 'omniauth/vkontakte'
2
4
  require 'omniauth/strategies/vkontakte/view_helper'
3
5
 
4
6
  module OmniAuth
5
7
  class Configuration
6
- attr_accessor :vkontakte_app_id
7
- attr_accessor :vkontakte_app_key
8
+ attr_accessor :vkontakte_app_id, :vkontakte_app_secret
8
9
  end
9
10
  end
10
11
 
11
12
  module OmniAuth
12
13
  module Strategies
13
- class Vkontakte
14
- include OmniAuth::Strategy
15
- include ViewHelper::PageHelper
14
+ class Vkontakte < OmniAuth::Strategies::OAuth2
15
+ # include OmniAuth::Strategy
16
+ # include ViewHelper::PageHelper
16
17
 
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)
18
+ # def initialize(app, app_id, app_key, options = {})
19
+ # @options = options
20
+ # OmniAuth.config.vkontakte_app_id = app_id
21
+ # OmniAuth.config.vkontakte_app_key = app_key
22
+ # super(app, :vkontakte)
23
+ # end
24
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
25
+ OmniAuth.config.vkontakte_app_id = client_id
26
+ OmniAuth.config.vkontakte_app_secret = client_secret
27
+
28
+ client_options = {
29
+ :site => 'http://api.vkontakte.ru',
30
+ :authorize_url => 'http://api.vkontakte.ru/oauth/authorize',
31
+ :access_token_url => 'https://api.vkontakte.ru/oauth/access_token'
32
+ }
33
+ super(app, :vkontakte, client_id, client_secret, client_options, options, &block)
34
+ end
35
+
36
+ # attr_reader :app_id
37
+
38
+ def user_data
39
+ @data ||= MultiJson.decode(@access_token.get('/me', {}, { "Accept-Language" => "en-us,en;"}))
22
40
  end
23
-
24
- attr_reader :app_id
25
41
 
42
+ # def request_phase
43
+ # Rack::Response.new(vkontakte_login_page).finish
44
+ # end
26
45
  def request_phase
27
- Rack::Response.new(vkontakte_login_page).finish
46
+ options[:scope] ||= "offline"
47
+ super
28
48
  end
29
-
49
+
30
50
  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
- puts Digest::MD5.new.hexdigest(args.sort.join('') + OmniAuth.config.vkontakte_app_key)
38
- puts sig
39
- return fail!(:invalid_credentials) unless Digest::MD5.new.hexdigest(args.sort.join('') + OmniAuth.config.vkontakte_app_key) == sig[4..-1]
40
- super
51
+ if request.params['error'] || request.params['error_reason']
52
+ raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
53
+ end
54
+
55
+ verifier = request.params['code']
56
+ puts "!!!!!!!!!"
57
+ puts client.access_token_url
58
+ # @access_token = client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
59
+ response = client.request(:get, client.access_token_url, {'client_id' => OmniAuth.config.vkontakte_app_id, 'client_secret' => OmniAuth.config.vkontakte_app_secret, 'code' => verifier})
60
+
61
+ puts "!!!!!"
62
+ puts MultiJson.decode(response)
63
+
64
+ # if @access_token.expires? && @access_token.expires_in <= 0
65
+ # client.request(:post, client.access_token_url, {
66
+ # 'client_id' => client_id,
67
+ # 'grant_type' => 'refresh_token',
68
+ # 'client_secret' => client_secret,
69
+ # 'refresh_token' => @access_token.refresh_token
70
+ # })
71
+ # @access_token = client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
72
+ # end
73
+ #
74
+ # super
75
+ # rescue ::OAuth2::HTTPError, ::OAuth2::AccessDenied, CallbackError => e
76
+ # fail!(:invalid_credentials, e)
77
+ # rescue ::MultiJson::DecodeError => e
78
+ # fail!(:invalid_response, e)
41
79
  end
80
+
81
+ # def callback_phase
82
+ # app_cookie = request.cookies["vk_app_#{OmniAuth.config.vkontakte_app_id}"]
83
+ # return fail!(:invalid_credentials) unless app_cookie
84
+ # args = app_cookie.split("&")
85
+ # sig_index = args.index { |arg| arg =~ /^sig=/ }
86
+ # return fail!(:invalid_credentials) unless sig_index
87
+ # sig = args.delete_at(sig_index)
88
+ # puts Digest::MD5.new.hexdigest(args.sort.join('') + OmniAuth.config.vkontakte_app_key)
89
+ # puts sig
90
+ # return fail!(:invalid_credentials) unless Digest::MD5.new.hexdigest(args.sort.join('') + OmniAuth.config.vkontakte_app_key) == sig[4..-1]
91
+ # super
92
+ # end
42
93
 
43
94
  def auth_hash
44
95
  OmniAuth::Utils.deep_merge(super(), {
@@ -1,14 +1,12 @@
1
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
2
+ class OmniAuth::Strategies::Vkontakte < OmniAuth::Strategies::OAuth2
3
+ class ViewHelper
4
+ module PageHelper
5
+ def vkontakte_login_page
6
+ vkontakte_header +
7
+ vkontakte_login_button +
8
+ vkontakte_footer
9
+ end
12
10
 
13
11
  def vkontakte_header
14
12
  <<-HEADER
@@ -123,8 +121,9 @@ BUTTON
123
121
  </body></html>
124
122
  FOOTER
125
123
  end
126
- end
127
- end
128
124
  end
129
125
  end
130
126
  end
127
+ # end
128
+ # end
129
+ # end
data/oa-vkontakte.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.homepage = %q{http://github.com/oruen/oa-vkontakte}
13
13
  s.rubyforge_project = %q{oa-vkontakte}
14
14
 
15
- s.add_dependency(%q<oa-core>, [">= 0.1.6"])
15
+ s.add_dependency(%q<oa-core>, [">= 0.2.0.beta4"])
16
16
  s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
17
17
  s.add_development_dependency(%q<yard>, [">= 0"])
18
18
  s.add_development_dependency(%q<rack-test>, ["~> 0.5.6"])
@@ -0,0 +1,74 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{oa-vkontakte_alexandrov}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Igor Alexandrov"]
12
+ s.date = %q{2011-07-22}
13
+ s.description = %q{Include this gem into your project with OmniAuth gem and you will get VKontakte login in one line of code.}
14
+ s.email = %q{igor.alexandrov@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/oa-vkontakte.rb",
26
+ "lib/omniauth/strategies/vkontakte.rb",
27
+ "lib/omniauth/strategies/vkontakte/view_helper.rb",
28
+ "lib/omniauth/vkontakte.rb",
29
+ "oa-vkontakte.gemspec",
30
+ "oa-vkontakte_alexandrov.gemspec",
31
+ "spec/oa-vkontakte_spec.rb",
32
+ "spec/omniauth/strategires/vkontakte_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/igor-alexandrov/oa-vkontakte}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.6.2}
39
+ s.summary = %q{VKontakte OmniAuth module with view helpers}
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<omniauth>, [">= 0.2.0.beta4"])
46
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
49
+ s.add_development_dependency(%q<rcov>, [">= 0"])
50
+ s.add_runtime_dependency(%q<oa-core>, [">= 0.2.0.beta4"])
51
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
52
+ s.add_development_dependency(%q<yard>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<omniauth>, [">= 0.2.0.beta4"])
55
+ s.add_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
58
+ s.add_dependency(%q<rcov>, [">= 0"])
59
+ s.add_dependency(%q<oa-core>, [">= 0.2.0.beta4"])
60
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
61
+ s.add_dependency(%q<yard>, [">= 0"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<omniauth>, [">= 0.2.0.beta4"])
65
+ s.add_dependency(%q<shoulda>, [">= 0"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
68
+ s.add_dependency(%q<rcov>, [">= 0"])
69
+ s.add_dependency(%q<oa-core>, [">= 0.2.0.beta4"])
70
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
71
+ s.add_dependency(%q<yard>, [">= 0"])
72
+ end
73
+ end
74
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa-vkontakte_alexandrov
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Igor Alexandrov
@@ -15,29 +15,109 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-17 00:00:00 +03:00
18
+ date: 2011-07-22 00:00:00 +04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: oa-core
23
22
  prerelease: false
23
+ type: :runtime
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 62196363
30
+ segments:
31
+ - 0
32
+ - 2
33
+ - 0
34
+ - beta
35
+ - 4
36
+ version: 0.2.0.beta4
37
+ name: omniauth
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ prerelease: false
41
+ type: :development
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ name: shoulda
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ prerelease: false
55
+ type: :development
56
+ requirement: &id003 !ruby/object:Gem::Requirement
25
57
  none: false
26
58
  requirements:
27
59
  - - ~>
28
60
  - !ruby/object:Gem::Version
29
- hash: 19
61
+ hash: 23
30
62
  segments:
63
+ - 1
31
64
  - 0
65
+ - 0
66
+ version: 1.0.0
67
+ name: bundler
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ prerelease: false
71
+ type: :development
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 7
78
+ segments:
32
79
  - 1
80
+ - 6
33
81
  - 4
34
- version: 0.1.4
82
+ version: 1.6.4
83
+ name: jeweler
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ prerelease: false
87
+ type: :development
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ name: rcov
98
+ version_requirements: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ prerelease: false
35
101
  type: :runtime
36
- version_requirements: *id001
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 62196363
108
+ segments:
109
+ - 0
110
+ - 2
111
+ - 0
112
+ - beta
113
+ - 4
114
+ version: 0.2.0.beta4
115
+ name: oa-core
116
+ version_requirements: *id006
37
117
  - !ruby/object:Gem::Dependency
38
- name: rspec
39
118
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
119
+ type: :development
120
+ requirement: &id007 !ruby/object:Gem::Requirement
41
121
  none: false
42
122
  requirements:
43
123
  - - ">="
@@ -48,12 +128,12 @@ dependencies:
48
128
  - 2
49
129
  - 9
50
130
  version: 1.2.9
51
- type: :development
52
- version_requirements: *id002
131
+ name: rspec
132
+ version_requirements: *id007
53
133
  - !ruby/object:Gem::Dependency
54
- name: yard
55
134
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
135
+ type: :development
136
+ requirement: &id008 !ruby/object:Gem::Requirement
57
137
  none: false
58
138
  requirements:
59
139
  - - ">="
@@ -62,8 +142,8 @@ dependencies:
62
142
  segments:
63
143
  - 0
64
144
  version: "0"
65
- type: :development
66
- version_requirements: *id003
145
+ name: yard
146
+ version_requirements: *id008
67
147
  description: Include this gem into your project with OmniAuth gem and you will get VKontakte login in one line of code.
68
148
  email: igor.alexandrov@gmail.com
69
149
  executables: []
@@ -84,6 +164,7 @@ files:
84
164
  - lib/omniauth/strategies/vkontakte/view_helper.rb
85
165
  - lib/omniauth/vkontakte.rb
86
166
  - oa-vkontakte.gemspec
167
+ - oa-vkontakte_alexandrov.gemspec
87
168
  - spec/oa-vkontakte_spec.rb
88
169
  - spec/omniauth/strategires/vkontakte_spec.rb
89
170
  - spec/spec_helper.rb
@@ -117,11 +198,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
198
  requirements: []
118
199
 
119
200
  rubyforge_project:
120
- rubygems_version: 1.5.2
201
+ rubygems_version: 1.6.2
121
202
  signing_key:
122
203
  specification_version: 3
123
204
  summary: VKontakte OmniAuth module with view helpers
124
- test_files:
125
- - spec/oa-vkontakte_spec.rb
126
- - spec/omniauth/strategires/vkontakte_spec.rb
127
- - spec/spec_helper.rb
205
+ test_files: []
206
+