oa-webmoney 0.0.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
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+
9
+ group :development do
10
+ gem "rspec", "~> 2.5.0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.5.2"
13
+ gem 'webmoney', '~> 0.0.10'
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.2)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ nokogiri (1.4.4)
11
+ rake (0.8.7)
12
+ rspec (2.5.0)
13
+ rspec-core (~> 2.5.0)
14
+ rspec-expectations (~> 2.5.0)
15
+ rspec-mocks (~> 2.5.0)
16
+ rspec-core (2.5.1)
17
+ rspec-expectations (2.5.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.5.0)
20
+ webmoney (0.0.10)
21
+ nokogiri
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ bundler (~> 1.0.0)
28
+ jeweler (~> 1.5.2)
29
+ rspec (~> 2.5.0)
30
+ webmoney (~> 0.0.10)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Anton
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.md ADDED
@@ -0,0 +1,85 @@
1
+ = oa-webmoney
2
+
3
+ === Usage with Devise
4
+
5
+ Original help page[https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview]
6
+
7
+ Gemfile
8
+
9
+ gem 'oa-webmoney'
10
+
11
+ adding wmid column:
12
+
13
+ rails g migration add_wmid_to_user
14
+
15
+ and add this:
16
+
17
+ def self.up
18
+ add_column :users, :wmid, :string, :limit => 12
19
+
20
+ add_index :users, :wmid, :unique => true
21
+ end
22
+
23
+ def self.down
24
+ remove_column :users, :wmid
25
+ end
26
+
27
+ devise.rb
28
+
29
+ config.omniauth :webmoney, :credentials => { :site_holder_wmid => 'your_site_wmid',
30
+ :app_rids => { 'localhost' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
31
+ 'example.com' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' }}, :mode => Rails.env)
32
+
33
+ user.rb
34
+
35
+ devise :omniauthable
36
+
37
+ def self.find_for_webmoney_oauth(access_token, signed_in_resource=nil)
38
+ data = access_token['extra']
39
+ if user = User.find_by_wmid(data[:WmLogin_WMID])
40
+ user
41
+ else # Create an user with a stub password.
42
+ User.create!(:email => "#{data[:WmLogin_WMID]}@wmkeeper.com", :password => Devise.friendly_token[0,20])
43
+ end
44
+ end
45
+
46
+ add link to authorize:
47
+
48
+ <%= link_to "Sign in with Webmoney", user_omniauth_authorize_path(:webmoney) %>
49
+
50
+ routes.rb
51
+
52
+ devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
53
+
54
+ app/controllers/users/omniauth_callbacks_controller.rb
55
+
56
+ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
57
+ def webmoney
58
+ # You need to implement the method below in your model
59
+ @user = User.find_for_webmoney_oauth(env["omniauth.auth"], current_user)
60
+
61
+ if @user.persisted?
62
+ flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Webmoney"
63
+ sign_in_and_redirect @user, :event => :authentication
64
+ else
65
+ session["devise.webmoney_data"] = env["omniauth.auth"]
66
+ redirect_to new_user_registration_url
67
+ end
68
+ end
69
+ end
70
+
71
+ == Contributing to oa-webmoney
72
+
73
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
74
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
75
+ * Fork the project
76
+ * Start a feature/bugfix branch
77
+ * Commit and push until you are happy with your contribution
78
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
79
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
80
+
81
+ == Copyright
82
+
83
+ Copyright (c) 2011 Anton. See LICENSE.txt for
84
+ further details.
85
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "oa-webmoney"
16
+ gem.homepage = "http://github.com/skyeagle/oa-webmoney"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Webmoney}
19
+ gem.description = %Q{Webmoney}
20
+ gem.email = "eagle.anton@gmail.com"
21
+ gem.authors = ["Anton"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'webmoney', '~> 0.0.10'
25
+ gem.add_development_dependency 'rspec', '> 2.5.02.5.0'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ task :default => :spec
36
+
37
+ require 'rake/rdoctask'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "oa-webmoney #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,6 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ # tell OmniAuth to load our strategy
4
+ autoload :Webmoney, 'oa-webmoney/webmoney'
5
+ end
6
+ end
@@ -0,0 +1,121 @@
1
+ require 'omniauth/core'
2
+ require 'webmoney'
3
+ module OmniAuth
4
+ module Strategies
5
+ class Webmoney
6
+ include OmniAuth::Strategy
7
+ class WmLib
8
+ include ::Webmoney
9
+ end
10
+
11
+ ERROR_MESSAGES = {
12
+ # -3 unknown response
13
+ :server_not_available => "Unknown response",
14
+ # -2 raised network error
15
+ :server_not_available => "Sorry, the Webmoney Login server is not available",
16
+ # -1
17
+ :internal_error => "Webmoney Login server internal error",
18
+ # 1
19
+ :invalid_arguments => "Invalid arguments",
20
+ # 2
21
+ :ticket_invalid => "Sorry, invalid authorization ticket",
22
+ # 3
23
+ :ticket_expired => "Sorry, authorization ticket expired",
24
+ # 4
25
+ :user_not_found => "Sorry, user not found",
26
+ # 5
27
+ :holder_not_found => "The holder of a site not found",
28
+ # 6
29
+ :website_not_found => "Website Not Found",
30
+ # 7
31
+ :url_not_found => "This url is not found, or does not belong to the site",
32
+ # 8
33
+ :settings_not_found => "Security Settings for the site could not be found",
34
+ # 9
35
+ :invalid_password => "Access service is not authorized. Invalid password.",
36
+ # 10
37
+ :not_trusted => "Attempting to gain access to the site, which does not accept you as a trustee",
38
+ # 11
39
+ :pwd_access_blocked => "Password access to the service blocked",
40
+ # 12
41
+ :user_blocked => "The user is temporarily blocked. Probably made the selection Ticket",
42
+ # 201
43
+ :ip_differs => "Ip address in the request differs from the address, which was an authorized user"
44
+ }
45
+
46
+ def initialize(app, opts = {})
47
+ @credentials = opts[:credentials]
48
+ @mode = opts[:mode]
49
+ @wm_instance = if defined?(Rails)
50
+ Rails.webmoney
51
+ else
52
+ WmLib.new(:wmid => @credentials[:site_holder_wmid])
53
+ end
54
+ super(app, :webmoney, opts)
55
+ end
56
+
57
+ def request_phase
58
+ r = Rack::Response.new
59
+ r.redirect "https://login.wmtransfer.com/GateKeeper.aspx?RID=#{credentials[:app_rids][request.host]}"
60
+ r.finish
61
+ end
62
+
63
+ def callback_phase
64
+ wminfo =
65
+ { :WmLogin_Ticket => request.params["WmLogin_Ticket"],
66
+ :WmLogin_UrlID => request.params["WmLogin_UrlID"],
67
+ :WmLogin_Expire => request.params["WmLogin_Expires"],
68
+ :WmLogin_AuthType => request.params["WmLogin_AuthType"],
69
+ :WmLogin_LastAccess => request.params["WmLogin_LastAccess"],
70
+ :WmLogin_Created => request.params["WmLogin_Created"],
71
+ :WmLogin_WMID => request.params["WmLogin_WMID"],
72
+ :WmLogin_UserAddress => request.params["WmLogin_UserAddress"] }
73
+
74
+ # work around for local development
75
+ ip_to_check = %w(development test).include?(mode) ? wminfo[:WmLogin_UserAddress] : request.ip
76
+
77
+ check_req_params = wminfo.merge({:remote_ip => ip_to_check})
78
+
79
+ begin
80
+ response = wm_instance.request(:login, check_req_params)[:retval]
81
+ rescue Errno::ECONNRESET, Errno::ECONNREFUSED, Timeout::Error => e
82
+ logger.info("Rack webmoney exception: #{e}")
83
+ response = -2
84
+ rescue ::Webmoney::ResultError => e
85
+ logger.info("Rack webmoney exception: #{e}")
86
+ response = wm_instance.error
87
+ end
88
+
89
+ status = case response
90
+ when 0 then :successful
91
+ when -3 then :unknown_response
92
+ when -2 then :server_not_available
93
+ when -1 then :internal_error
94
+ when 1 then :invalid_arguments
95
+ when 2 then :ticket_invalid
96
+ when 3 then :ticket_expired
97
+ when 4 then :user_not_found
98
+ when 5 then :holder_not_found
99
+ when 6 then :website_not_found
100
+ when 7 then :url_not_found
101
+ when 8 then :settings_not_found
102
+ when 9 then :invalid_password
103
+ when 10 then :not_trusted
104
+ when 11 then :pwd_access_blocked
105
+ when 12 then :user_blocked
106
+ when 201 then :ip_differs
107
+ end
108
+
109
+ return fail!(status, ERROR_MESSAGES[status]) unless status == :successful
110
+
111
+ super
112
+ end
113
+
114
+ def auth_hash
115
+ OmniAuth::Utils.deep_merge(super(), {
116
+ 'uid' => @wminfo[:WmLogin_WMID],
117
+ 'extra' => @wminfo})
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,72 @@
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-webmoney}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Anton"]
12
+ s.date = %q{2011-02-18}
13
+ s.description = %q{Webmoney}
14
+ s.email = %q{eagle.anton@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/oa-webmoney.rb",
29
+ "lib/oa-webmoney/webmoney.rb",
30
+ "oa-webmoney.gemspec",
31
+ "spec/oa-webmoney_spec.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/skyeagle/oa-webmoney}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{Webmoney}
39
+ s.test_files = [
40
+ "spec/oa-webmoney_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
52
+ s.add_development_dependency(%q<webmoney>, ["~> 0.0.10"])
53
+ s.add_runtime_dependency(%q<webmoney>, ["~> 0.0.10"])
54
+ s.add_development_dependency(%q<rspec>, ["> 2.5.02.5.0"])
55
+ else
56
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
59
+ s.add_dependency(%q<webmoney>, ["~> 0.0.10"])
60
+ s.add_dependency(%q<webmoney>, ["~> 0.0.10"])
61
+ s.add_dependency(%q<rspec>, ["> 2.5.02.5.0"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
65
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
67
+ s.add_dependency(%q<webmoney>, ["~> 0.0.10"])
68
+ s.add_dependency(%q<webmoney>, ["~> 0.0.10"])
69
+ s.add_dependency(%q<rspec>, ["> 2.5.02.5.0"])
70
+ end
71
+ end
72
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "OaWebmoney" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'oa-webmoney'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oa-webmoney
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ version: 0.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Anton
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-18 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 5
30
+ - 0
31
+ version: 2.5.0
32
+ type: :development
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: jeweler
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 5
60
+ - 2
61
+ version: 1.5.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: webmoney
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ - 0
75
+ - 10
76
+ version: 0.0.10
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ name: webmoney
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ - 0
90
+ - 10
91
+ version: 0.0.10
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">"
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 2
104
+ - 5
105
+ - 2
106
+ - 5
107
+ - 0
108
+ version: 2.5.02.5.0
109
+ type: :development
110
+ prerelease: false
111
+ version_requirements: *id006
112
+ description: Webmoney
113
+ email: eagle.anton@gmail.com
114
+ executables: []
115
+
116
+ extensions: []
117
+
118
+ extra_rdoc_files:
119
+ - LICENSE.txt
120
+ - README.md
121
+ files:
122
+ - .document
123
+ - .rspec
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - VERSION
130
+ - lib/oa-webmoney.rb
131
+ - lib/oa-webmoney/webmoney.rb
132
+ - oa-webmoney.gemspec
133
+ - spec/oa-webmoney_spec.rb
134
+ - spec/spec_helper.rb
135
+ has_rdoc: true
136
+ homepage: http://github.com/skyeagle/oa-webmoney
137
+ licenses:
138
+ - MIT
139
+ post_install_message:
140
+ rdoc_options: []
141
+
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ hash: -871235757
150
+ segments:
151
+ - 0
152
+ version: "0"
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ requirements: []
162
+
163
+ rubyforge_project:
164
+ rubygems_version: 1.3.7
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: Webmoney
168
+ test_files:
169
+ - spec/oa-webmoney_spec.rb
170
+ - spec/spec_helper.rb