easy_auth-oauth2 0.1.1 → 0.2.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: 188ffef0c79a6b0f8e5230d1891d5292a108d1a6
4
+ data.tar.gz: ac3e432197a7d1e1837128d45ce98fa6bfc3bc15
5
+ SHA512:
6
+ metadata.gz: 94d92289bb5422fe66d5f257ebb1e1fca5707d713dcc50474a48eb4415dd230f924bf71b7ec37d4f2eb1dd05f50f1acee9f703af313b861543eef676644e844f
7
+ data.tar.gz: 22b8bfcd96b60fe858d31a4fd168233d26ac6a93aab9b37fd66a0cf64736fde8dc29fae8ddb1f58f3e9d0e7619f8876078bf9062662883ee830a4e86e48522b0
@@ -1,30 +1,21 @@
1
+ require 'easy_auth-oauth_core'
1
2
  require 'oauth2'
2
3
 
3
4
  module EasyAuth::Models::Identities::Oauth2::Base
4
- def self.included(base)
5
- base.class_eval do
6
- extend ClassMethods
7
- end
8
- end
5
+ extend ActiveSupport::Concern
6
+ include EasyAuth::Models::Identities::OauthCore
9
7
 
10
8
  module ClassMethods
11
9
  def authenticate(controller)
12
- if controller.params[:code].present? && controller.params[:error].blank?
13
- callback_url = controller.oauth2_callback_url(:provider => provider)
14
- code = controller.params[:code]
15
- token = client.auth_code.get_token(code, token_options(callback_url))
16
- user_info = get_user_info(token)
17
- identity = self.find_or_initialize_by_username user_info['id'].to_s
18
- identity.token = token.token
19
- account = controller.current_account
20
-
21
- if identity.new_record?
22
- account = EasyAuth.account_model.create(EasyAuth.account_model.identity_username_attribute => identity.username) if account.nil?
23
- identity.account = account
24
- end
25
-
26
- identity.save!
27
- identity
10
+ super(controller) do
11
+ callback_url = controller.oauth2_callback_url(:provider => provider)
12
+ code = controller.params[:code]
13
+ token = client.auth_code.get_token(code, token_options(callback_url), token_params)
14
+ account_attributes = get_account_attributes(token)
15
+ identity = self.find_or_initialize_by(:uid => retrieve_uid(account_attributes))
16
+ identity.token = token.token
17
+
18
+ [identity, account_attributes]
28
19
  end
29
20
  end
30
21
 
@@ -32,22 +23,33 @@ module EasyAuth::Models::Identities::Oauth2::Base
32
23
  controller.redirect_to authenticate_url(controller.oauth2_callback_url(:provider => provider))
33
24
  end
34
25
 
26
+ def can_authenticate?(controller)
27
+ controller.params[:code].present? && controller.params[:error].blank?
28
+ end
29
+
35
30
  def get_access_token(identity)
36
31
  ::OAuth2::AccessToken.new client, identity.token
37
32
  end
38
33
 
39
- private
34
+ def version
35
+ :oauth2
36
+ end
37
+
38
+ def oauth2_scope
39
+ ''
40
+ end
40
41
 
41
42
  def token_options(callback_url)
42
43
  { :redirect_uri => callback_url }
43
44
  end
44
45
 
45
- def get_user_info(token)
46
- ActiveSupport::JSON.decode(token.get(user_info_url).body)
46
+ # Needed by some OAuth2 providers the use custom query parameters
47
+ def token_params
48
+ {}
47
49
  end
48
50
 
49
- def provider
50
- raise NotImplementedError
51
+ def get_account_attributes(token)
52
+ ActiveSupport::JSON.decode(token.get(account_attributes_url).body)
51
53
  end
52
54
 
53
55
  def client
@@ -55,10 +57,10 @@ module EasyAuth::Models::Identities::Oauth2::Base
55
57
  end
56
58
 
57
59
  def authenticate_url(callback_url)
58
- client.auth_code.authorize_url(:redirect_uri => callback_url, :scope => scope)
60
+ client.auth_code.authorize_url(:redirect_uri => callback_url, :scope => oauth2_scope)
59
61
  end
60
62
 
61
- def user_info_url
63
+ def account_attributes_url
62
64
  raise NotImplementedError
63
65
  end
64
66
 
@@ -73,29 +75,5 @@ module EasyAuth::Models::Identities::Oauth2::Base
73
75
  def site_url
74
76
  raise NotImplementedError
75
77
  end
76
-
77
- def scope
78
- settings.scope
79
- end
80
-
81
- def client_id
82
- settings.client_id
83
- end
84
-
85
- def secret
86
- settings.secret
87
- end
88
-
89
- def settings
90
- EasyAuth.oauth2[provider]
91
- end
92
-
93
- def provider
94
- self.to_s.split('::').last.underscore.to_sym
95
- end
96
- end
97
-
98
- def get_access_token
99
- self.class.get_access_token self
100
78
  end
101
79
  end
@@ -43,8 +43,8 @@ module EasyAuth
43
43
 
44
44
  self.oauth2 = {}
45
45
 
46
- def self.oauth2_client(provider, client_id, secret, scope = '')
47
- oauth2[provider] = OpenStruct.new :client_id => client_id, :secret => secret, :scope => scope || ''
46
+ def self.oauth2_client(provider, client_id, secret)
47
+ oauth2[provider] = OpenStruct.new :client_id => client_id, :secret => secret
48
48
  end
49
49
  end
50
50
 
@@ -2,15 +2,15 @@ module EasyAuth::Oauth2::Controllers::Sessions
2
2
 
3
3
  private
4
4
 
5
- def after_successful_sign_in_with_oauth2(identity)
6
- send("after_successful_sign_in_with_oauth2_for_#{params[:provider]}", identity)
5
+ def after_successful_sign_in_with_oauth2
6
+ send("after_successful_sign_in_with_oauth2_for_#{params[:provider]}")
7
7
  end
8
8
 
9
- def after_successful_sign_in_url_with_oauth2(identity)
10
- send("after_successful_sign_in_url_with_oauth2_for_#{params[:provider]}", identity)
9
+ def after_successful_sign_in_url_with_oauth2
10
+ send("after_successful_sign_in_url_with_oauth2_for_#{params[:provider]}")
11
11
  end
12
12
 
13
- def after_failed_sign_in_with_oauth2(identity)
14
- send("after_failed_sign_in_with_oauth2_for_#{params[:provider]}", identity)
13
+ def after_failed_sign_in_with_oauth2
14
+ send("after_failed_sign_in_with_oauth2_for_#{params[:provider]}")
15
15
  end
16
16
  end
@@ -1,5 +1,5 @@
1
1
  module EasyAuth
2
2
  module Oauth2
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_auth-oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brian Cardarella
@@ -10,136 +9,134 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-11-15 00:00:00.000000000 Z
12
+ date: 2014-03-11 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: easy_auth
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ~>
21
19
  - !ruby/object:Gem::Version
22
- version: 0.2.0
20
+ version: 0.3.0
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ~>
29
26
  - !ruby/object:Gem::Version
30
- version: 0.2.0
27
+ version: 0.3.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: easy_auth-oauth_core
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
31
42
  - !ruby/object:Gem::Dependency
32
43
  name: oauth2
33
44
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
45
  requirements:
36
46
  - - ~>
37
47
  - !ruby/object:Gem::Version
38
- version: 0.8.0
48
+ version: 0.9.1
39
49
  type: :runtime
40
50
  prerelease: false
41
51
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
52
  requirements:
44
53
  - - ~>
45
54
  - !ruby/object:Gem::Version
46
- version: 0.8.0
55
+ version: 0.9.1
47
56
  - !ruby/object:Gem::Dependency
48
57
  name: rspec
49
58
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
59
  requirements:
52
- - - ! '>='
60
+ - - '>='
53
61
  - !ruby/object:Gem::Version
54
62
  version: '0'
55
63
  type: :development
56
64
  prerelease: false
57
65
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
66
  requirements:
60
- - - ! '>='
67
+ - - '>='
61
68
  - !ruby/object:Gem::Version
62
69
  version: '0'
63
70
  - !ruby/object:Gem::Dependency
64
71
  name: sqlite3
65
72
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
73
  requirements:
68
- - - ! '>='
74
+ - - '>='
69
75
  - !ruby/object:Gem::Version
70
76
  version: '0'
71
77
  type: :development
72
78
  prerelease: false
73
79
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
80
  requirements:
76
- - - ! '>='
81
+ - - '>='
77
82
  - !ruby/object:Gem::Version
78
83
  version: '0'
79
84
  - !ruby/object:Gem::Dependency
80
85
  name: database_cleaner
81
86
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
87
  requirements:
84
- - - ! '>='
88
+ - - '>='
85
89
  - !ruby/object:Gem::Version
86
90
  version: '0'
87
91
  type: :development
88
92
  prerelease: false
89
93
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
94
  requirements:
92
- - - ! '>='
95
+ - - '>='
93
96
  - !ruby/object:Gem::Version
94
97
  version: '0'
95
98
  - !ruby/object:Gem::Dependency
96
99
  name: valid_attribute
97
100
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
101
  requirements:
100
- - - ! '>='
102
+ - - '>='
101
103
  - !ruby/object:Gem::Version
102
104
  version: '0'
103
105
  type: :development
104
106
  prerelease: false
105
107
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
108
  requirements:
108
- - - ! '>='
109
+ - - '>='
109
110
  - !ruby/object:Gem::Version
110
111
  version: '0'
111
112
  - !ruby/object:Gem::Dependency
112
113
  name: factory_girl
113
114
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
115
  requirements:
116
116
  - - ~>
117
117
  - !ruby/object:Gem::Version
118
- version: 2.6.0
118
+ version: 4.2.0
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
122
  requirements:
124
123
  - - ~>
125
124
  - !ruby/object:Gem::Version
126
- version: 2.6.0
125
+ version: 4.2.0
127
126
  - !ruby/object:Gem::Dependency
128
- name: bourne
127
+ name: mocha
129
128
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
129
  requirements:
132
- - - ! '>='
130
+ - - ~>
133
131
  - !ruby/object:Gem::Version
134
- version: '0'
132
+ version: 0.10.5
135
133
  type: :development
136
134
  prerelease: false
137
135
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
136
  requirements:
140
- - - ! '>='
137
+ - - ~>
141
138
  - !ruby/object:Gem::Version
142
- version: '0'
139
+ version: 0.10.5
143
140
  description: EasyAuth-Oauth2
144
141
  email:
145
142
  - brian@dockyard.com
@@ -165,32 +162,25 @@ files:
165
162
  - README.md
166
163
  homepage: https://github.com/dockyard/easy_auth-oauth2
167
164
  licenses: []
165
+ metadata: {}
168
166
  post_install_message:
169
167
  rdoc_options: []
170
168
  require_paths:
171
169
  - lib
172
170
  required_ruby_version: !ruby/object:Gem::Requirement
173
- none: false
174
171
  requirements:
175
- - - ! '>='
172
+ - - '>='
176
173
  - !ruby/object:Gem::Version
177
174
  version: '0'
178
- segments:
179
- - 0
180
- hash: -1473449787249200133
181
175
  required_rubygems_version: !ruby/object:Gem::Requirement
182
- none: false
183
176
  requirements:
184
- - - ! '>='
177
+ - - '>='
185
178
  - !ruby/object:Gem::Version
186
179
  version: '0'
187
- segments:
188
- - 0
189
- hash: -1473449787249200133
190
180
  requirements: []
191
181
  rubyforge_project:
192
- rubygems_version: 1.8.23
182
+ rubygems_version: 2.0.3
193
183
  signing_key:
194
- specification_version: 3
184
+ specification_version: 4
195
185
  summary: EasyAuth-Oauth2
196
186
  test_files: []