svenfuchs-devise_oauth2_authenticatable 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{svenfuchs-devise_oauth2_authenticatable}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["bhbryant"]
@@ -27,7 +27,6 @@ module Devise #:nodoc:
27
27
  klass = mapping.to
28
28
  begin
29
29
 
30
-
31
30
  # Verify User Auth code and get access token from auth server: will error on failue
32
31
  access_token = Devise::oauth2_client.web_server.get_access_token(
33
32
  params[:code], :redirect_uri => Devise::session_sign_in_url(request,mapping)
@@ -38,9 +37,13 @@ module Devise #:nodoc:
38
37
  # Get user details from OAuth2 Service
39
38
  oauth2_user_attributes = JSON.parse(access_token.get(OAUTH2_CONFIG['user_attributes_path']))
40
39
 
41
- user = klass.authenticate_with_oauth2(oauth2_user_attributes['id'], access_token.token)
42
-
40
+ # find uid from user attributes
41
+ oauth2_uid_field = OAUTH2_CONFIG['user_attribute_uid_key'] || 'id'
42
+ oauth2_uid = oauth2_uid_field.split('/').inject(oauth2_user_attributes) do |attributes, key|
43
+ attributes[key] rescue {}
44
+ end || raise("can not find #{oauth2_uid_field.inspect} in #{oauth2_user_attributes.inspect}")
43
45
 
46
+ user = klass.authenticate_with_oauth2(oauth2_uid, access_token.token)
44
47
 
45
48
  if user.present?
46
49
  user.on_after_oauth2_connect(oauth2_user_attributes)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svenfuchs-devise_oauth2_authenticatable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - bhbryant