sorcery 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sorcery might be problematic. Click here for more details.

Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +60 -4
  4. data/CHANGELOG.md +15 -1
  5. data/Gemfile +9 -18
  6. data/Gemfile.rails4 +8 -10
  7. data/README.md +31 -11
  8. data/VERSION +1 -1
  9. data/gemfiles/active_record-rails41.gemfile +6 -0
  10. data/gemfiles/mongo_mapper-rails41.gemfile +8 -0
  11. data/gemfiles/mongoid-rails41.gemfile +11 -0
  12. data/lib/sorcery.rb +20 -28
  13. data/lib/sorcery/controller.rb +6 -11
  14. data/lib/sorcery/controller/submodules/external.rb +30 -15
  15. data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
  16. data/lib/sorcery/model.rb +102 -70
  17. data/lib/sorcery/model/adapters/active_record.rb +7 -2
  18. data/lib/sorcery/model/adapters/datamapper.rb +123 -0
  19. data/lib/sorcery/model/adapters/mongo_mapper.rb +8 -4
  20. data/lib/sorcery/model/adapters/mongoid.rb +6 -6
  21. data/lib/sorcery/model/submodules/activity_logging.rb +24 -0
  22. data/lib/sorcery/model/submodules/brute_force_protection.rb +16 -0
  23. data/lib/sorcery/model/submodules/remember_me.rb +19 -4
  24. data/lib/sorcery/model/submodules/reset_password.rb +30 -13
  25. data/lib/sorcery/model/submodules/user_activation.rb +53 -22
  26. data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
  27. data/lib/sorcery/protocols/oauth.rb +42 -0
  28. data/lib/sorcery/protocols/oauth2.rb +47 -0
  29. data/lib/sorcery/providers/base.rb +27 -0
  30. data/lib/sorcery/providers/facebook.rb +63 -0
  31. data/lib/sorcery/providers/github.rb +51 -0
  32. data/lib/sorcery/providers/google.rb +51 -0
  33. data/lib/sorcery/providers/linkedin.rb +66 -0
  34. data/lib/sorcery/providers/liveid.rb +53 -0
  35. data/lib/sorcery/providers/twitter.rb +59 -0
  36. data/lib/sorcery/providers/vk.rb +61 -0
  37. data/lib/sorcery/providers/xing.rb +64 -0
  38. data/lib/sorcery/test_helpers/internal.rb +3 -3
  39. data/lib/sorcery/test_helpers/internal/rails.rb +14 -3
  40. data/lib/sorcery/test_helpers/rails.rb +1 -10
  41. data/lib/sorcery/test_helpers/rails/controller.rb +17 -0
  42. data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
  43. data/sorcery.gemspec +14 -18
  44. data/spec/active_record/controller_activity_logging_spec.rb +5 -116
  45. data/spec/active_record/controller_brute_force_protection_spec.rb +69 -47
  46. data/spec/active_record/controller_http_basic_auth_spec.rb +24 -18
  47. data/spec/active_record/controller_oauth2_spec.rb +112 -187
  48. data/spec/active_record/controller_oauth_spec.rb +41 -37
  49. data/spec/active_record/controller_remember_me_spec.rb +39 -38
  50. data/spec/active_record/controller_session_timeout_spec.rb +31 -16
  51. data/spec/active_record/controller_spec.rb +4 -178
  52. data/spec/active_record/integration_spec.rb +1 -1
  53. data/spec/active_record/user_activation_spec.rb +1 -1
  54. data/spec/active_record/user_activity_logging_spec.rb +1 -1
  55. data/spec/active_record/user_brute_force_protection_spec.rb +1 -1
  56. data/spec/active_record/user_oauth_spec.rb +1 -1
  57. data/spec/active_record/user_remember_me_spec.rb +1 -1
  58. data/spec/active_record/user_reset_password_spec.rb +1 -1
  59. data/spec/active_record/user_spec.rb +7 -8
  60. data/spec/datamapper/controller_activity_logging_spec.rb +17 -0
  61. data/spec/datamapper/controller_spec.rb +8 -0
  62. data/spec/datamapper/user_activation_spec.rb +10 -0
  63. data/spec/datamapper/user_activity_logging_spec.rb +9 -0
  64. data/spec/datamapper/user_brute_force_protection_spec.rb +9 -0
  65. data/spec/datamapper/user_oauth_spec.rb +9 -0
  66. data/spec/datamapper/user_remember_me_spec.rb +8 -0
  67. data/spec/datamapper/user_reset_password_spec.rb +8 -0
  68. data/spec/datamapper/user_spec.rb +27 -0
  69. data/spec/mongo_mapper/controller_spec.rb +4 -171
  70. data/spec/mongo_mapper/user_activation_spec.rb +1 -2
  71. data/spec/mongo_mapper/user_activity_logging_spec.rb +1 -1
  72. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +1 -1
  73. data/spec/mongo_mapper/user_oauth_spec.rb +1 -1
  74. data/spec/mongo_mapper/user_remember_me_spec.rb +1 -1
  75. data/spec/mongo_mapper/user_reset_password_spec.rb +1 -1
  76. data/spec/mongo_mapper/user_spec.rb +7 -8
  77. data/spec/mongoid/controller_activity_logging_spec.rb +4 -99
  78. data/spec/mongoid/controller_spec.rb +4 -182
  79. data/spec/mongoid/user_activation_spec.rb +1 -2
  80. data/spec/mongoid/user_activity_logging_spec.rb +1 -2
  81. data/spec/mongoid/user_brute_force_protection_spec.rb +1 -2
  82. data/spec/mongoid/user_oauth_spec.rb +1 -2
  83. data/spec/mongoid/user_remember_me_spec.rb +1 -2
  84. data/spec/mongoid/user_reset_password_spec.rb +1 -2
  85. data/spec/mongoid/user_spec.rb +8 -9
  86. data/spec/orm/active_record.rb +2 -0
  87. data/spec/orm/datamapper.rb +34 -0
  88. data/spec/orm/mongo_mapper.rb +1 -0
  89. data/spec/orm/mongoid.rb +1 -0
  90. data/spec/rails_app/app/controllers/sorcery_controller.rb +64 -59
  91. data/spec/rails_app/app/datamapper/authentication.rb +8 -0
  92. data/spec/rails_app/app/datamapper/user.rb +7 -0
  93. data/spec/rails_app/config/routes.rb +18 -13
  94. data/spec/shared_examples/controller_activity_logging_shared_examples.rb +125 -0
  95. data/spec/shared_examples/controller_oauth2_shared_examples.rb +32 -36
  96. data/spec/shared_examples/controller_oauth_shared_examples.rb +19 -26
  97. data/spec/shared_examples/controller_shared_examples.rb +203 -0
  98. data/spec/shared_examples/user_activation_shared_examples.rb +107 -90
  99. data/spec/shared_examples/user_activity_logging_shared_examples.rb +10 -10
  100. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +14 -13
  101. data/spec/shared_examples/user_oauth_shared_examples.rb +23 -15
  102. data/spec/shared_examples/user_remember_me_shared_examples.rb +32 -23
  103. data/spec/shared_examples/user_reset_password_shared_examples.rb +136 -115
  104. data/spec/shared_examples/user_shared_examples.rb +206 -146
  105. data/spec/sorcery_crypto_providers_spec.rb +28 -28
  106. data/spec/spec_helper.rb +15 -6
  107. metadata +83 -127
  108. data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
  109. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -50
  110. data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
  111. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -99
  112. data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -93
  113. data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -92
  114. data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -103
  115. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -93
  116. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -94
  117. data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -101
  118. data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -98
  119. data/lib/sorcery/test_helpers.rb +0 -5
@@ -1,46 +0,0 @@
1
- require 'oauth'
2
- module Sorcery
3
- module Controller
4
- module Submodules
5
- module External
6
- module Protocols
7
- module Oauth1
8
- def oauth_version
9
- "1.0"
10
- end
11
-
12
- def get_request_token(token=nil,secret=nil)
13
- return ::OAuth::RequestToken.new(get_consumer(), token, secret) if token && secret
14
-
15
- get_consumer.get_request_token(:oauth_callback => @callback_url)
16
- end
17
-
18
- def authorize_url(args)
19
- get_request_token(
20
- args[:request_token],
21
- args[:request_token_secret]
22
- ).authorize_url({
23
- :oauth_callback => @callback_url
24
- })
25
- end
26
-
27
- def get_access_token(args)
28
- get_request_token(
29
- args[:request_token],
30
- args[:request_token_secret]
31
- ).get_access_token({
32
- :oauth_verifier => args[:oauth_verifier]
33
- })
34
- end
35
-
36
- protected
37
-
38
- def get_consumer
39
- ::OAuth::Consumer.new(@key, @secret, :site => @site)
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,50 +0,0 @@
1
- require 'oauth2'
2
- module Sorcery
3
- module Controller
4
- module Submodules
5
- module External
6
- module Protocols
7
- module Oauth2
8
- def oauth_version
9
- "2.0"
10
- end
11
-
12
- def authorize_url(options = {})
13
- client = build_client(options)
14
- client.auth_code.authorize_url(
15
- :redirect_uri => @callback_url,
16
- :scope => @scope,
17
- :display => @display,
18
- :state => @state
19
- )
20
- end
21
-
22
- def get_access_token(args, options = {})
23
- client = build_client(options)
24
- client.auth_code.get_token(
25
- args[:code],
26
- {
27
- :redirect_uri => @callback_url,
28
- :parse => options.delete(:parse)
29
- },
30
- options
31
- )
32
- end
33
-
34
- def build_client(options = {})
35
- defaults = {
36
- :site => @site,
37
- :ssl => { :ca_file => Config.ca_file }
38
- }
39
- ::OAuth2::Client.new(
40
- @key,
41
- @secret,
42
- defaults.merge!(options)
43
- )
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,21 +0,0 @@
1
- module Sorcery
2
- module Controller
3
- module Submodules
4
- module External
5
- module Providers
6
- module Base
7
- module BaseClient
8
- def self.included(base)
9
- base.module_eval do
10
- class << self
11
- attr_accessor :original_callback_url
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,99 +0,0 @@
1
- module Sorcery
2
- module Controller
3
- module Submodules
4
- module External
5
- module Providers
6
- # This module adds support for OAuth with facebook.com.
7
- # When included in the 'config.providers' option, it adds a new option, 'config.facebook'.
8
- # Via this new option you can configure Facebook specific settings like your app's key and secret.
9
- #
10
- # config.facebook.key = <key>
11
- # config.facebook.secret = <secret>
12
- # ...
13
- #
14
- module Facebook
15
- def self.included(base)
16
- base.module_eval do
17
- class << self
18
- attr_reader :facebook # access to facebook_client.
19
-
20
- def merge_facebook_defaults!
21
- @defaults.merge!(:@facebook => FacebookClient)
22
- end
23
- end
24
- merge_facebook_defaults!
25
- update!
26
- end
27
- end
28
-
29
- module FacebookClient
30
- include Base::BaseClient
31
- class << self
32
- attr_accessor :key,
33
- :secret,
34
- :callback_url,
35
- :site,
36
- :user_info_path,
37
- :scope,
38
- :user_info_mapping,
39
- :display,
40
- :access_permissions,
41
- :state
42
- attr_reader :access_token
43
-
44
- include Protocols::Oauth2
45
-
46
- def init
47
- @site = "https://graph.facebook.com"
48
- @user_info_path = "/me"
49
- @scope = "email,offline_access"
50
- @user_info_mapping = {}
51
- @display = "page"
52
- @token_url = "oauth/access_token"
53
- @mode = :query
54
- @parse = :query
55
- @param_name = "access_token"
56
- end
57
-
58
- def get_user_hash(access_token)
59
- user_hash = {}
60
- response = access_token.get(@user_info_path)
61
- user_hash[:user_info] = JSON.parse(response.body)
62
- user_hash[:uid] = user_hash[:user_info]['id']
63
- user_hash
64
- end
65
-
66
- def has_callback?
67
- true
68
- end
69
-
70
- # calculates and returns the url to which the user should be redirected,
71
- # to get authenticated at the external provider's site.
72
- def login_url(params,session)
73
- self.authorize_url
74
- end
75
-
76
- # overrides oauth2#authorize_url to allow customized scope.
77
- def authorize_url
78
- @scope = self.access_permissions.present? ? self.access_permissions.join(",") : @scope
79
- super
80
- end
81
-
82
- # tries to login the user from access token
83
- def process_callback(params,session)
84
- args = {}
85
- options = { :token_url => @token_url, :mode => @mode, :param_name => @param_name, :parse => @parse }
86
- args.merge!({:code => params[:code]}) if params[:code]
87
- return self.get_access_token(args, options)
88
- end
89
-
90
- end
91
- init
92
- end
93
-
94
- end
95
- end
96
- end
97
- end
98
- end
99
- end
@@ -1,93 +0,0 @@
1
- module Sorcery
2
- module Controller
3
- module Submodules
4
- module External
5
- module Providers
6
- # This module adds support for OAuth with github.com.
7
- # When included in the 'config.providers' option, it adds a new option, 'config.github'.
8
- # Via this new option you can configure Github specific settings like your app's key and secret.
9
- #
10
- # config.github.key = <key>
11
- # config.github.secret = <secret>
12
- # ...
13
- #
14
- module Github
15
- def self.included(base)
16
- base.module_eval do
17
- class << self
18
- attr_reader :github # access to github_client.
19
-
20
- def merge_github_defaults!
21
- @defaults.merge!(:@github => GithubClient)
22
- end
23
- end
24
- merge_github_defaults!
25
- update!
26
- end
27
- end
28
-
29
- module GithubClient
30
- include Base::BaseClient
31
- class << self
32
- attr_accessor :key,
33
- :secret,
34
- :callback_url,
35
- :auth_path,
36
- :token_path,
37
- :site,
38
- :scope,
39
- :user_info_path,
40
- :user_info_mapping,
41
- :state
42
- attr_reader :access_token
43
-
44
- include Protocols::Oauth2
45
-
46
- def init
47
- @site = "https://github.com/"
48
- @user_info_path = "https://api.github.com/user"
49
- @scope = nil
50
- @auth_path = "/login/oauth/authorize"
51
- @token_path = "/login/oauth/access_token"
52
- @user_info_mapping = {}
53
- end
54
-
55
- def get_user_hash(access_token)
56
- user_hash = {}
57
- response = access_token.get(@user_info_path)
58
- user_hash[:user_info] = JSON.parse(response.body)
59
- user_hash[:uid] = user_hash[:user_info]['id']
60
- user_hash
61
- end
62
-
63
- def has_callback?
64
- true
65
- end
66
-
67
- # calculates and returns the url to which the user should be redirected,
68
- # to get authenticated at the external provider's site.
69
- def login_url(params,session)
70
- self.authorize_url({:authorize_url => @auth_path})
71
- end
72
-
73
- # tries to login the user from access token
74
- def process_callback(params,session)
75
- args = {}
76
- args.merge!({:code => params[:code]}) if params[:code]
77
- options = {
78
- :token_url => @token_path,
79
- :token_method => :post
80
- }
81
- return self.get_access_token(args, options)
82
- end
83
-
84
- end
85
- init
86
- end
87
-
88
- end
89
- end
90
- end
91
- end
92
- end
93
- end
@@ -1,92 +0,0 @@
1
- module Sorcery
2
- module Controller
3
- module Submodules
4
- module External
5
- module Providers
6
- # This module adds support for OAuth with google.com.
7
- # When included in the 'config.providers' option, it adds a new option, 'config.google'.
8
- # Via this new option you can configure Google specific settings like your app's key and secret.
9
- #
10
- # config.google.key = <key>
11
- # config.google.secret = <secret>
12
- # ...
13
- #
14
- module Google
15
- def self.included(base)
16
- base.module_eval do
17
- class << self
18
- attr_reader :google # access to google_client.
19
-
20
- def merge_google_defaults!
21
- @defaults.merge!(:@google => GoogleClient)
22
- end
23
- end
24
- merge_google_defaults!
25
- update!
26
- end
27
- end
28
-
29
- module GoogleClient
30
- include Base::BaseClient
31
- class << self
32
- attr_accessor :key,
33
- :secret,
34
- :callback_url,
35
- :site,
36
- :auth_url,
37
- :token_path,
38
- :user_info_url,
39
- :scope,
40
- :user_info_mapping,
41
- :state
42
- attr_reader :access_token
43
-
44
- include Protocols::Oauth2
45
-
46
- def init
47
- @site = "https://accounts.google.com"
48
- @auth_url = "/o/oauth2/auth"
49
- @token_url = "/o/oauth2/token"
50
- @user_info_url = "https://www.googleapis.com/oauth2/v1/userinfo"
51
- @scope = "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
52
- @user_info_mapping = {}
53
- end
54
-
55
- def get_user_hash(access_token)
56
- user_hash = {}
57
- response = access_token.get(@user_info_url)
58
- user_hash[:user_info] = JSON.parse(response.body)
59
- user_hash[:uid] = user_hash[:user_info]['id']
60
- user_hash
61
- end
62
-
63
- def has_callback?
64
- true
65
- end
66
-
67
- # calculates and returns the url to which the user should be redirected,
68
- # to get authenticated at the external provider's site.
69
- def login_url(params,session)
70
- self.authorize_url({:authorize_url => @auth_url})
71
- end
72
-
73
- # tries to login the user from access token
74
- def process_callback(params,session)
75
- args = {}
76
- args.merge!({:code => params[:code]}) if params[:code]
77
- options = {
78
- :token_url => @token_url,
79
- :token_method => :post
80
- }
81
- return self.get_access_token(args, options)
82
- end
83
- end
84
- init
85
- end
86
-
87
- end
88
- end
89
- end
90
- end
91
- end
92
- end
@@ -1,103 +0,0 @@
1
- module Sorcery
2
- module Controller
3
- module Submodules
4
- module External
5
- module Providers
6
- # This module adds support for OAuth with Linkedin.com.
7
- # When included in the 'config.providers' option, it adds a new option, 'config.linkedin'.
8
- # Via this new option you can configure Linkedin specific settings like your app's key and secret.
9
- #
10
- # config.linkedin.key = <key>
11
- # config.linkedin.secret = <secret>
12
- # ...
13
- #
14
- module Linkedin
15
- def self.included(base)
16
- base.module_eval do
17
- class << self
18
- attr_reader :linkedin
19
-
20
- def merge_linkedin_defaults!
21
- @defaults.merge!(:@linkedin => LinkedinClient)
22
- end
23
- end
24
- merge_linkedin_defaults!
25
- update!
26
- end
27
- end
28
-
29
- module LinkedinClient
30
- include Base::BaseClient
31
- class << self
32
- attr_accessor :key,
33
- :secret,
34
- :callback_url,
35
- :site,
36
- :authorize_path,
37
- :request_token_path,
38
- :access_token_path,
39
- :user_info_path,
40
- :user_info_mapping,
41
- :user_info_fields,
42
- :access_permissions,
43
- :state
44
- attr_reader :access_token
45
-
46
- include Protocols::Oauth1
47
-
48
- # Override included get_consumer method to provide authorize_path
49
- def get_consumer
50
- # Add access permissions to request token path
51
- @configuration[:request_token_path] += "?scope=" + self.access_permissions.join('+') unless self.access_permissions.blank? or @configuration[:request_token_path].include? "?scope="
52
- ::OAuth::Consumer.new(@key, @secret, @configuration)
53
- end
54
-
55
- def init
56
- @configuration = {
57
- site: "https://api.linkedin.com",
58
- authorize_path: '/uas/oauth/authenticate',
59
- request_token_path: '/uas/oauth/requestToken',
60
- access_token_path: '/uas/oauth/accessToken'
61
- }
62
- @user_info_path = "/v1/people/~"
63
- end
64
-
65
- def get_user_hash(access_token)
66
- user_hash = {}
67
- fields = self.user_info_fields.join(',')
68
- response = access_token.get("#{@user_info_path}:(#{fields})", 'x-li-format' => 'json')
69
- user_hash[:user_info] = JSON.parse(response.body)
70
- user_hash[:uid] = user_hash[:user_info]['id'].to_s
71
- user_hash
72
- end
73
-
74
- def has_callback?
75
- true
76
- end
77
-
78
- # calculates and returns the url to which the user should be redirected,
79
- # to get authenticated at the external provider's site.
80
- def login_url(params,session)
81
- req_token = self.get_request_token
82
- session[:request_token] = req_token.token
83
- session[:request_token_secret] = req_token.secret
84
- self.authorize_url({:request_token => req_token.token, :request_token_secret => req_token.secret})
85
- end
86
-
87
- # tries to login the user from access token
88
- def process_callback(params,session)
89
- args = {}
90
- args.merge!({:oauth_verifier => params[:oauth_verifier], :request_token => session[:request_token], :request_token_secret => session[:request_token_secret]})
91
- args.merge!({:code => params[:code]}) if params[:code]
92
- return self.get_access_token(args)
93
- end
94
-
95
- end
96
- init
97
- end
98
- end
99
- end
100
- end
101
- end
102
- end
103
- end