exvo-auth 0.14.0 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,17 @@
1
- # OAuth2
1
+ # exvo-auth
2
+
3
+ This gem is Exvo's implementation of the oauth2 protocole for handling user authentication across Exvo apps.
4
+
5
+
6
+
7
+ ## Requirements
8
+
9
+ * Runs on Ruby 1.8.7 & 1.9.2 (preferred version)
10
+ * Rails 3.0+ (works with Rails 3.1) or Merb
11
+
12
+
13
+
14
+ ## OAuth2
2
15
 
3
16
  * Get familiar with [OmniAuth by Intridea](http://github.com/intridea/omniauth). Read about OAuth2.
4
17
  * Obtain `client_id` and `client_secret` for your app from Exvo.
@@ -13,8 +26,8 @@ The preferred way to configure the gem is via the ENV variables:
13
26
  ```ruby
14
27
  ENV['AUTH_CLIENT_ID'] = "foo"
15
28
  ENV['AUTH_CLIENT_SECRET'] = "bar"
16
- ENV['AUTH_DEBUG'] = true # [OPTIONAL] dumps all HTTP traffic to STDERR, useful during development
17
- ENV['AUTH_REQUIRE_SSL'] = false # [OPTIONAL] disable SSL, useful in development (note that all apps API urls must be http, not https)
29
+ ENV['AUTH_DEBUG'] = "true" # [OPTIONAL] dumps all HTTP traffic to STDERR, useful during development; it *has to be a string, not a boolean*
30
+ ENV['AUTH_REQUIRE_SSL'] = "false" # [OPTIONAL] disable SSL, useful in development (note that all apps API urls must be http, not https); it *has to be a string, not a boolean*
18
31
  ENV['AUTH_HOST'] = "test.exvo.com" # [OPTIONAL] override the default auth host
19
32
  ```
20
33
 
@@ -29,8 +42,8 @@ But you can also set things directly in the `config/application.rb` file (before
29
42
  ```ruby
30
43
  ExvoAuth::Config.client_id = "foo"
31
44
  ExvoAuth::Config.client_secret = "bar"
32
- ExvoAuth::Config.debug = true
33
- ExvoAuth::Config.require_ssl = false
45
+ ExvoAuth::Config.debug = true # boolean
46
+ ExvoAuth::Config.require_ssl = false # boolean
34
47
  ExvoAuth::Config.host = "test.exvo.com"
35
48
  ```
36
49
 
@@ -45,5 +45,7 @@ module ExvoAuth
45
45
  end
46
46
 
47
47
  OAuth2::Client.class_eval do
48
- def non_interactive; ExvoAuth::OAuth2::Strategy::NonInteractive.new(self) end
48
+ def non_interactive
49
+ ExvoAuth::OAuth2::Strategy::NonInteractive.new(self)
50
+ end
49
51
  end
@@ -1,6 +1,6 @@
1
1
  module ExvoAuth::Config
2
2
  def self.debug
3
- @@debug ||= ENV['AUTH_DEBUG'] || false
3
+ @@debug ||= (ENV['AUTH_DEBUG'] == 'true') || false
4
4
  end
5
5
 
6
6
  def self.debug=(debug)
@@ -49,7 +49,7 @@ module ExvoAuth::Config
49
49
  end
50
50
 
51
51
  def self.require_ssl
52
- @@require_ssl ||= ENV['AUTH_REQUIRE_SSL'] || default_opts[env.to_sym][:require_ssl]
52
+ @@require_ssl ||= (ENV['AUTH_REQUIRE_SSL'] == 'true') || default_opts[env.to_sym][:require_ssl]
53
53
  end
54
54
 
55
55
  def self.require_ssl=(require_ssl)
@@ -34,7 +34,7 @@ module ExvoAuth::Controllers::Base
34
34
  # Usuallly this method is called from your sessions#destroy.
35
35
  def sign_out_and_redirect!(return_to = "/")
36
36
  session.clear
37
- @current_user = nil
37
+ remove_instance_variable(:@current_user) if instance_variable_defined?(:@current_user)
38
38
  redirect_to sign_out_url(return_to)
39
39
  end
40
40
 
@@ -62,7 +62,7 @@ module ExvoAuth::Controllers::Base
62
62
  end
63
63
 
64
64
  def current_user
65
- return @current_user if defined?(@current_user)
65
+ return @current_user unless @current_user.nil?
66
66
  @current_user = session[:user_uid] && find_or_create_user_by_uid(session[:user_uid])
67
67
  end
68
68
 
@@ -69,4 +69,4 @@ class ExvoAuth::Models::Message
69
69
  !!id
70
70
  end
71
71
 
72
- end
72
+ end
@@ -2,16 +2,23 @@
2
2
  # current authentication with an OAuth2 provider, grant them access token,
3
3
  # otherwise - deny authentication.
4
4
  #
5
- # This is a simple, non-standard OAuth2 extension. It is similar to "web_server"
6
- # strategy with one exception: instead of redirecting following temporary token
7
- # requests to an interactive user interface it returns a negative answer:
8
- # when user is not signed in, or when app requests an extended scope
9
- # that doesn't match current authentication grant.
5
+ # This is a simple, non-standard OAuth2 extension. Instead of redirecting
6
+ # following temporary token requests to an interactive user interface it
7
+ # returns a negative answer when user is not signed in or when app requests
8
+ # an extended scope that doesn't match current authentication grant.
10
9
  #
11
10
  # This strategy is needed to sign users in during json/jsonp requests,
12
11
  # which cannot result in any interactive/navigational flows.
13
- class ExvoAuth::OAuth2::Strategy::NonInteractive < ::OAuth2::Strategy::WebServer
12
+ class ExvoAuth::OAuth2::Strategy::NonInteractive < ::OAuth2::Strategy::Base
14
13
  def authorize_params(options = {})
15
- super(options).merge('type' => 'non_interactive')
14
+ options.merge('type' => 'non_interactive').merge(client_params)
15
+ end
16
+
17
+ def authorize_url(params={})
18
+ @client.authorize_url(authorize_params.merge(params))
19
+ end
20
+
21
+ def get_token(code, params={}, opts={})
22
+ @client.get_token(client_params.merge(params), opts)
16
23
  end
17
24
  end
@@ -2,31 +2,46 @@ class ExvoAuth::Strategies::NonInteractive < ExvoAuth::Strategies::Base
2
2
  def initialize(app, options = {})
3
3
  super(app, :non_interactive, options)
4
4
  end
5
-
5
+
6
6
  def request_phase
7
7
  options[:redirect_uri] = callback_url if callback_url
8
8
  options[:scope] = request["scope"] if request["scope"]
9
9
  options[:state] = request["state"] if request["state"]
10
10
 
11
- redirect @client.non_interactive.authorize_url(options)
11
+ redirect client.non_interactive.authorize_url(options)
12
12
  end
13
-
13
+
14
14
  def callback_url
15
15
  key = ExvoAuth::Config.callback_key
16
16
  value = request[key]
17
-
17
+
18
18
  if value
19
19
  super + "?" + Rack::Utils.build_query(key => value)
20
20
  else
21
21
  super
22
22
  end
23
23
  end
24
-
25
- def fail!(message_key)
26
- body = MultiJson.encode(:error => "Please sign in!")
27
- [401, {
28
- "Content-Type" => "application/json",
29
- "Content-Length" => body.length.to_s
24
+
25
+ # FIXME this does not bubble up the 401 response code, although the error message is returned
26
+ def fail!(message_key, exception = nil)
27
+ error =
28
+ case message_key
29
+ when :invalid_credentials, :session_expired
30
+ "Please sign in."
31
+ when :invalid_response
32
+ "Invalid response from the authorization server. Please try again."
33
+ when :timeout
34
+ "Timeout occured. Please try again."
35
+ when :service_unavailable
36
+ "Authorization service is not available. Please try again later."
37
+ else
38
+ "Unknown error. Please try again."
39
+ end
40
+
41
+ body = MultiJson.encode(:error => error)
42
+ [401, {
43
+ "Content-Type" => "application/json",
44
+ "Content-Length" => body.length.to_s
30
45
  }, [body]]
31
46
  end
32
47
  end
@@ -1,3 +1,3 @@
1
1
  module ExvoAuth
2
- VERSION = "0.14.0"
2
+ VERSION = "0.14.1"
3
3
  end
@@ -66,4 +66,10 @@ class TestExvoAuth < Test::Unit::TestCase
66
66
  assert_equal host, ExvoAuth::Config.host
67
67
  ENV['AUTH_HOST'] = nil
68
68
  end
69
+
70
+ test "setting debugging using ENV key (boolean converted to string)" do
71
+ assert_equal false, ExvoAuth::Config.debug
72
+ ENV['AUTH_DEBUG'] = 'true'
73
+ assert_equal true, ExvoAuth::Config.debug
74
+ end
69
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exvo-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.14.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-09 00:00:00.000000000Z
12
+ date: 2012-01-03 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oa-oauth
16
- requirement: &85705040 !ruby/object:Gem::Requirement
16
+ requirement: &84259450 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.3.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *85705040
24
+ version_requirements: *84259450
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &85704480 !ruby/object:Gem::Requirement
27
+ requirement: &84257660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *85704480
35
+ version_requirements: *84257660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activemodel
38
- requirement: &85703260 !ruby/object:Gem::Requirement
38
+ requirement: &84254280 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *85703260
46
+ version_requirements: *84254280
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: actionpack
49
- requirement: &85702120 !ruby/object:Gem::Requirement
49
+ requirement: &84253250 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *85702120
57
+ version_requirements: *84253250
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mocha
60
- requirement: &85701560 !ruby/object:Gem::Requirement
60
+ requirement: &84252370 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *85701560
68
+ version_requirements: *84252370
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: test-unit
71
- requirement: &85700790 !ruby/object:Gem::Requirement
71
+ requirement: &84251420 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *85700790
79
+ version_requirements: *84251420
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: bundler
82
- requirement: &85700500 !ruby/object:Gem::Requirement
82
+ requirement: &84250100 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *85700500
90
+ version_requirements: *84250100
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rake
93
- requirement: &85699890 !ruby/object:Gem::Requirement
93
+ requirement: &84249320 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *85699890
101
+ version_requirements: *84249320
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: guard
104
- requirement: &85698850 !ruby/object:Gem::Requirement
104
+ requirement: &84248480 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *85698850
112
+ version_requirements: *84248480
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: guard-test
115
- requirement: &85691120 !ruby/object:Gem::Requirement
115
+ requirement: &84248080 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *85691120
123
+ version_requirements: *84248080
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rb-fsevent
126
- requirement: &85690210 !ruby/object:Gem::Requirement
126
+ requirement: &84247720 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *85690210
134
+ version_requirements: *84247720
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: rb-inotify
137
- requirement: &85689050 !ruby/object:Gem::Requirement
137
+ requirement: &84247320 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *85689050
145
+ version_requirements: *84247320
146
146
  description: Sign in with Exvo account
147
147
  email:
148
148
  - jacek.becela@gmail.com
@@ -203,3 +203,4 @@ signing_key:
203
203
  specification_version: 3
204
204
  summary: Sign in with Exvo account
205
205
  test_files: []
206
+ has_rdoc: