exvo-auth 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -78,6 +78,50 @@ class SessionsController < ApplicationController
78
78
  end
79
79
  ```
80
80
 
81
+ It's good to have your SessionsController#create action a little more extended, so that each time the user logs in into the app, his user data (like email, nickname) is updated from auth (his profile):
82
+
83
+ ```ruby
84
+ def create
85
+ auth = request.env["omniauth.auth"]
86
+
87
+ if user = User.find_by_uid(auth["uid"])
88
+ user.update_attributes!(auth["user_info"])
89
+ else
90
+ user = User.create(:uid => auth["uid"], :nickname => auth["user_info"]["nickname"], :email => auth["user_info"]["email"])
91
+ end
92
+
93
+ sign_in_and_redirect!
94
+ end
95
+ ```
96
+
97
+ This is what you get (and what you can use/save for the local user) from auth (example data as of 2011-12):
98
+
99
+ ```ruby
100
+ request.env["omniauth.auth"].inspect
101
+
102
+ { "provider" => "exvo",
103
+ "uid" => 1,
104
+ "credentials" => {
105
+ "token" => "a2d09701559b9f26a8284d6f94670477d882ad6d9f3d92ce9917262a6b54085fa3fb99e111340459"
106
+ },
107
+ "user_info" => {
108
+ "nickname" => "Pawel",
109
+ "email" => "pawel@exvo.com"
110
+ },
111
+ "extra" => {
112
+ "user_hash" => {
113
+ "id" => 1,
114
+ "nickname" => "Pawel",
115
+ "country_code" => nil,
116
+ "plan" => "admin",
117
+ "language" => "en",
118
+ "email" => "pawel@exvo.com",
119
+ "referring_user_id" => nil
120
+ }
121
+ }
122
+ }
123
+ ```
124
+
81
125
 
82
126
  ## Implement `#find_or_create_user_by_uid(uid)` in your Application Controller
83
127
 
@@ -91,9 +135,7 @@ def find_or_create_user_by_uid(uid)
91
135
  end
92
136
  ```
93
137
 
94
- Additional info (emails, etc) can be obtained using auth api (`/users/uid.json` path).
95
-
96
- In short: you get `params[:auth]`. Do what you want to do with it: store the data, create session, etc.
138
+ It's best to leave this method as it is (without updating any user data inside this method, better to do this in the SessionsController#create action). Updating user in this method might lead to some very hard to debug cyclic executions possibly leading to stack-level too deep errors and/or general slowness, so please proceed with extreme caution.
97
139
 
98
140
 
99
141
  ## Sign up and sign in paths for use in links
@@ -107,6 +149,19 @@ sign in path with a return address: "/auth/interactive?state=url" # using O
107
149
  You have a handy methods available in controllers (and views in Rails): `sign_in_path` and `sign_up_path`.
108
150
 
109
151
 
152
+ ## Require authentication in your controllers
153
+
154
+ In `application_controller` (for all controllers) or in some controller just add:
155
+
156
+ ```ruby
157
+ before_filter :authenticate_user!
158
+ ```
159
+
160
+ ## Fetching user information
161
+
162
+ All info about any particular user ca be obtained using auth api (`/users/uid.json` path).
163
+
164
+
110
165
  ## Read the source, there are few features not mentioned in this README
111
166
 
112
167
 
@@ -14,10 +14,10 @@ Gem::Specification.new do |s|
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.rubyforge_project = "exvo-auth"
16
16
 
17
- s.add_dependency "oa-oauth", "~> 0.0.4"
18
- s.add_dependency "httparty", "~> 0.6.1"
19
- s.add_dependency "activemodel", "~> 3.0.0"
20
- s.add_dependency "actionpack", "~> 3.0.0"
17
+ s.add_dependency "oa-oauth", "~> 0.3.2"
18
+ s.add_dependency "httparty"
19
+ s.add_dependency "activemodel", "~> 3.0"
20
+ s.add_dependency "actionpack", "~> 3.0"
21
21
 
22
22
  s.add_development_dependency "mocha"
23
23
  s.add_development_dependency "test-unit"
@@ -66,10 +66,6 @@ module ExvoAuth::Config
66
66
  @@env = env
67
67
  end
68
68
 
69
- def self.cfs_id
70
- "fb0e7bd5864aa0186630212d800af8a6"
71
- end
72
-
73
69
  private
74
70
 
75
71
  def self.default_opts
@@ -17,7 +17,7 @@ module ExvoAuth::Controllers::Base
17
17
 
18
18
  # Usually this method is called from your sessions#create.
19
19
  def sign_in_and_redirect!
20
- session[:user_uid] = request.env["rack.request.query_hash"]["auth"]["uid"]
20
+ session[:user_uid] = request.env["omniauth.auth"]["uid"]
21
21
 
22
22
  url = if params[:state] == "popup"
23
23
  ExvoAuth::Config.uri + "/close_popup.html"
@@ -3,7 +3,8 @@ class ExvoAuth::Strategies::Base < OmniAuth::Strategies::OAuth2
3
3
  options[:site] ||= ExvoAuth::Config.uri
4
4
  options[:client_id] ||= ExvoAuth::Config.client_id
5
5
  options[:client_secret] ||= ExvoAuth::Config.client_secret
6
-
6
+ options[:token_url] ||= "/oauth/access_token"
7
+
7
8
  if options[:site].nil? || options[:client_id].nil? || options[:client_secret].nil?
8
9
  raise(ArgumentError, "Please configure uri, client_id and client_secret")
9
10
  end
@@ -12,7 +13,8 @@ class ExvoAuth::Strategies::Base < OmniAuth::Strategies::OAuth2
12
13
  end
13
14
 
14
15
  def user_data
15
- @data ||= MultiJson.decode(@access_token.get('/user.json'))
16
+ @access_token.options.merge!({:param_name => :access_token, :mode => :query})
17
+ @data ||= MultiJson.decode(@access_token.get('/user.json').body)
16
18
  end
17
19
 
18
20
  def user_info
@@ -30,11 +32,4 @@ class ExvoAuth::Strategies::Base < OmniAuth::Strategies::OAuth2
30
32
  'extra' => { 'user_hash' => user_data }
31
33
  })
32
34
  end
33
-
34
- protected
35
-
36
- # Have a better name? Let me know!
37
- def unicorns_and_rainbows(hash)
38
- hash.reject{|k, v| v.nil?}
39
- end
40
35
  end
@@ -3,11 +3,10 @@ class ExvoAuth::Strategies::Interactive < ExvoAuth::Strategies::Base
3
3
  super(app, :interactive, options)
4
4
  end
5
5
 
6
- def request_phase(options = {})
7
- super(unicorns_and_rainbows(
8
- :scope => request["scope"],
9
- :state => request["state"],
10
- :x_sign_up => request["x_sign_up"]
11
- ))
6
+ def request_phase
7
+ options[:scope] = request["scope"] if request["scope"]
8
+ options[:state] = request["state"] if request["state"]
9
+ options[:x_sign_up] = request["x_sign_up"] if request["x_sign_up"]
10
+ super
12
11
  end
13
12
  end
@@ -3,12 +3,12 @@ class ExvoAuth::Strategies::NonInteractive < ExvoAuth::Strategies::Base
3
3
  super(app, :non_interactive, options)
4
4
  end
5
5
 
6
- def request_phase(options = {})
7
- redirect @client.non_interactive.authorize_url(unicorns_and_rainbows(
8
- :redirect_uri => callback_url,
9
- :scope => request["scope"],
10
- :state => request["state"]
11
- ))
6
+ def request_phase
7
+ options[:redirect_uri] = callback_url if callback_url
8
+ options[:scope] = request["scope"] if request["scope"]
9
+ options[:state] = request["state"] if request["state"]
10
+
11
+ redirect @client.non_interactive.authorize_url(options)
12
12
  end
13
13
 
14
14
  def callback_url
@@ -1,3 +1,3 @@
1
1
  module ExvoAuth
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  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.13.0
4
+ version: 0.14.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,55 +9,55 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-03 00:00:00.000000000Z
12
+ date: 2011-12-09 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oa-oauth
16
- requirement: &83727760 !ruby/object:Gem::Requirement
16
+ requirement: &85705040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.0.4
21
+ version: 0.3.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *83727760
24
+ version_requirements: *85705040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &83727530 !ruby/object:Gem::Requirement
27
+ requirement: &85704480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ~>
30
+ - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 0.6.1
32
+ version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *83727530
35
+ version_requirements: *85704480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activemodel
38
- requirement: &83727300 !ruby/object:Gem::Requirement
38
+ requirement: &85703260 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: 3.0.0
43
+ version: '3.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *83727300
46
+ version_requirements: *85703260
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: actionpack
49
- requirement: &83727070 !ruby/object:Gem::Requirement
49
+ requirement: &85702120 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.0
54
+ version: '3.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *83727070
57
+ version_requirements: *85702120
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mocha
60
- requirement: &83726880 !ruby/object:Gem::Requirement
60
+ requirement: &85701560 !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: *83726880
68
+ version_requirements: *85701560
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: test-unit
71
- requirement: &83726650 !ruby/object:Gem::Requirement
71
+ requirement: &85700790 !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: *83726650
79
+ version_requirements: *85700790
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: bundler
82
- requirement: &83726440 !ruby/object:Gem::Requirement
82
+ requirement: &85700500 !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: *83726440
90
+ version_requirements: *85700500
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rake
93
- requirement: &83726230 !ruby/object:Gem::Requirement
93
+ requirement: &85699890 !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: *83726230
101
+ version_requirements: *85699890
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: guard
104
- requirement: &83726020 !ruby/object:Gem::Requirement
104
+ requirement: &85698850 !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: *83726020
112
+ version_requirements: *85698850
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: guard-test
115
- requirement: &83725810 !ruby/object:Gem::Requirement
115
+ requirement: &85691120 !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: *83725810
123
+ version_requirements: *85691120
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rb-fsevent
126
- requirement: &83725600 !ruby/object:Gem::Requirement
126
+ requirement: &85690210 !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: *83725600
134
+ version_requirements: *85690210
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: rb-inotify
137
- requirement: &83725390 !ruby/object:Gem::Requirement
137
+ requirement: &85689050 !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: *83725390
145
+ version_requirements: *85689050
146
146
  description: Sign in with Exvo account
147
147
  email:
148
148
  - jacek.becela@gmail.com
@@ -169,7 +169,6 @@ files:
169
169
  - lib/exvo_auth/dejavu.rb
170
170
  - lib/exvo_auth/middleware.rb
171
171
  - lib/exvo_auth/models/message.rb
172
- - lib/exvo_auth/models/sharing.rb
173
172
  - lib/exvo_auth/oauth2.rb
174
173
  - lib/exvo_auth/session_store.rb
175
174
  - lib/exvo_auth/strategies/base.rb
@@ -1,20 +0,0 @@
1
- # TODO: activemodel with validations
2
- class ExvoAuth::Models::Sharing
3
- def self.create(attrs = {})
4
- new(attrs).save
5
- end
6
-
7
- protected
8
-
9
- def save
10
- if true
11
- cfs.post("/sharings", :query => { :document_id => attrs[:document_id], :sharing => { :email => attrs[:email], :user_uid => attrs[:user_uid] } })
12
- else
13
- # TODO: append errors on errors from cfs too.
14
- end
15
- end
16
-
17
- def cfs
18
- @cfs ||= Autonomous::Consumer.new(:app_id => Config.cfs_id)
19
- end
20
- end