svenfuchs-devise_oauth2_authenticatable 0.1.3 → 0.1.4

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.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["bhbryant"]
@@ -1,7 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require 'devise/strategies/base'
3
3
 
4
-
5
4
  module Devise #:nodoc:
6
5
  module Oauth2Authenticatable #:nodoc:
7
6
  module Strategies #:nodoc:
@@ -10,15 +9,10 @@ module Devise #:nodoc:
10
9
  # Redirects to sign_in page if it's not authenticated
11
10
  #
12
11
  class Oauth2Authenticatable < ::Devise::Strategies::Base
13
-
14
-
15
-
16
12
  # Without a oauth session authentication cannot proceed.
17
13
  #
18
14
  def valid?
19
-
20
15
  valid_controller? && valid_params? && mapping.to.respond_to?('authenticate_with_oauth2')
21
-
22
16
  end
23
17
 
24
18
  # Authenticate user with OAuth2
@@ -29,8 +23,8 @@ module Devise #:nodoc:
29
23
 
30
24
  # Verify User Auth code and get access token from auth server: will error on failue
31
25
  access_token = Devise::oauth2_client.web_server.get_access_token(
32
- params[:code], :redirect_uri => Devise::session_sign_in_url(request,mapping)
33
- )
26
+ params[:code], :redirect_uri => Devise::session_sign_in_url(request,mapping)
27
+ )
34
28
 
35
29
  # retrieve user attributes
36
30
 
@@ -48,33 +42,21 @@ module Devise #:nodoc:
48
42
  if user.present?
49
43
  user.on_after_oauth2_connect(oauth2_user_attributes)
50
44
  success!(user)
51
- else
52
- if klass.oauth2_auto_create_account?
53
-
54
-
55
-
56
- user = returning(klass.new) do |u|
57
- u.store_oauth2_credentials!(
58
- :token => access_token.token,
59
- :uid => oauth2_user_attributes['id']
60
- )
61
- u.on_before_oauth2_auto_create(oauth2_user_attributes)
62
- end
63
-
64
- begin
65
-
66
-
67
- user.save(true)
68
- user.on_after_oauth2_connect(oauth2_user_attributes)
69
-
45
+ elsif klass.oauth2_auto_create_account?
46
+ user = klass.new.tap do |u|
47
+ u.store_oauth2_credentials!(:token => access_token.token, :uid => oauth2_uid)
48
+ u.on_before_oauth2_auto_create(oauth2_user_attributes)
49
+ end
70
50
 
71
- success!(user)
72
- rescue
73
- fail!(:oauth2_invalid)
74
- end
75
- else
51
+ begin
52
+ user.save(true)
53
+ user.on_after_oauth2_connect(oauth2_user_attributes)
54
+ success!(user)
55
+ rescue
76
56
  fail!(:oauth2_invalid)
77
57
  end
58
+ else
59
+ fail!(:oauth2_invalid)
78
60
  end
79
61
 
80
62
  rescue => e
@@ -82,10 +64,8 @@ module Devise #:nodoc:
82
64
  end
83
65
  end
84
66
 
85
-
86
-
87
-
88
67
  protected
68
+
89
69
  def valid_controller?
90
70
  # params[:controller] == 'sessions'
91
71
  mapping.controllers[:sessions] == params[:controller]
@@ -94,10 +74,10 @@ module Devise #:nodoc:
94
74
  def valid_params?
95
75
  params[:code].present?
96
76
  end
97
-
98
77
  end
99
78
  end
100
79
  end
101
80
  end
102
81
 
103
82
  Warden::Strategies.add(:oauth2_authenticatable, Devise::Oauth2Authenticatable::Strategies::Oauth2Authenticatable)
83
+
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: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - bhbryant