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,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 microsoft liveid
7
- # When included in the 'config.providers' option, it adds a new option, 'config.liveid'.
8
- # Via this new option you can configure LiveId specific settings like your app's key and secret.
9
- #
10
- # config.liveid.key = <key>
11
- # config.liveid.secret = <secret>
12
- # ...
13
- #
14
- module Liveid
15
- def self.included(base)
16
- base.module_eval do
17
- class << self
18
- attr_reader :liveid # access to liveid_client.
19
-
20
- def merge_liveid_defaults!
21
- @defaults.merge!(:@liveid => LiveidClient)
22
- end
23
- end
24
- merge_liveid_defaults!
25
- update!
26
- end
27
- end
28
-
29
- module LiveidClient
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://oauth.live.com/"
48
- @auth_url = "/authorize"
49
- @token_path = "/token"
50
- @user_info_url = "https://apis.live.net/v5.0/me"
51
- @scope = "wl.basic wl.emails wl.offline_access"
52
- @user_info_mapping = {}
53
- end
54
-
55
- def get_user_hash(access_token)
56
- user_hash = {}
57
- access_token.token_param = "access_token"
58
- response = access_token.get(@user_info_url)
59
- user_hash[:user_info] = JSON.parse(response.body)
60
- user_hash[:uid] = user_hash[:user_info]['id']
61
- user_hash
62
- end
63
-
64
- def has_callback?
65
- true
66
- end
67
-
68
- # calculates and returns the url to which the user should be redirected,
69
- # to get authenticated at the external provider's site.
70
- def login_url(params,session)
71
- self.authorize_url({:authorize_url => @auth_url})
72
- end
73
-
74
- # tries to login the user from access token
75
- def process_callback(params,session)
76
- args = {}
77
- args.merge!({:code => params[:code]}) if params[:code]
78
- options = {
79
- :access_token_path => @token_path,
80
- :access_token_method => :post
81
- }
82
- return self.get_access_token(args, options)
83
- end
84
- end
85
- init
86
- end
87
-
88
- end
89
- end
90
- end
91
- end
92
- end
93
- end
@@ -1,94 +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 Twitter.com.
7
- # When included in the 'config.providers' option, it adds a new option, 'config.twitter'.
8
- # Via this new option you can configure Twitter specific settings like your app's key and secret.
9
- #
10
- # config.twitter.key = <key>
11
- # config.twitter.secret = <secret>
12
- # ...
13
- #
14
- module Twitter
15
- def self.included(base)
16
- base.module_eval do
17
- class << self
18
- attr_reader :twitter
19
- # def twitter(&blk) # allows block syntax.
20
- # yield @twitter
21
- # end
22
-
23
- def merge_twitter_defaults!
24
- @defaults.merge!(:@twitter => TwitterClient)
25
- end
26
- end
27
- merge_twitter_defaults!
28
- update!
29
- end
30
- end
31
-
32
- module TwitterClient
33
- include Base::BaseClient
34
- class << self
35
- attr_accessor :key,
36
- :secret,
37
- :callback_url,
38
- :site,
39
- :user_info_path,
40
- :user_info_mapping,
41
- :state
42
- attr_reader :access_token
43
-
44
- include Protocols::Oauth1
45
-
46
- # Override included get_consumer method to provide authorize_path
47
- def get_consumer
48
- ::OAuth::Consumer.new(@key, @secret, :site => @site, :authorize_path => "/oauth/authenticate")
49
- end
50
-
51
- def init
52
- @site = "https://api.twitter.com"
53
- @user_info_path = "/1.1/account/verify_credentials.json"
54
- @user_info_mapping = {}
55
- end
56
-
57
- def get_user_hash(access_token)
58
- user_hash = {}
59
- response = access_token.get(@user_info_path)
60
- user_hash[:user_info] = JSON.parse(response.body)
61
- user_hash[:uid] = user_hash[:user_info]['id'].to_s
62
- user_hash
63
- end
64
-
65
- def has_callback?
66
- true
67
- end
68
-
69
- # calculates and returns the url to which the user should be redirected,
70
- # to get authenticated at the external provider's site.
71
- def login_url(params, session)
72
- req_token = self.get_request_token
73
- session[:request_token] = req_token.token
74
- session[:request_token_secret] = req_token.secret
75
- self.authorize_url({:request_token => req_token.token, :request_token_secret => req_token.secret})
76
- end
77
-
78
- # tries to login the user from access token
79
- def process_callback(params, session)
80
- args = {}
81
- args.merge!({:oauth_verifier => params[:oauth_verifier], :request_token => session[:request_token], :request_token_secret => session[:request_token_secret]})
82
- args.merge!({:code => params[:code]}) if params[:code]
83
- return self.get_access_token(args)
84
- end
85
-
86
- end
87
- init
88
- end
89
- end
90
- end
91
- end
92
- end
93
- end
94
- end
@@ -1,101 +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 vk.com.
7
- # When included in the 'config.providers' option, it adds a new option, 'config.vk'.
8
- # Via this new option you can configure Vk specific settings like your app's key and secret.
9
- #
10
- # config.vk.key = <key>
11
- # config.vk.secret = <secret>
12
- # ...
13
- #
14
- module Vk
15
- def self.included(base)
16
- base.module_eval do
17
- class << self
18
- attr_reader :vk # access to vk_client.
19
-
20
- def merge_vk_defaults!
21
- @defaults.merge!(:@vk => VkClient)
22
- end
23
- end
24
- merge_vk_defaults!
25
- update!
26
- end
27
- end
28
-
29
- module VkClient
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
- :user_info_mapping,
39
- :state
40
- attr_reader :access_token
41
-
42
- include Protocols::Oauth2
43
-
44
- def init
45
- @site = "https://oauth.vk.com/"
46
- @user_info_url = "https://api.vk.com/method/getProfiles"
47
- @auth_path = "/authorize"
48
- @token_path = "/access_token"
49
- @user_info_mapping = {}
50
- end
51
-
52
- def get_user_hash(access_token)
53
- user_hash = {}
54
-
55
- params = {
56
- :access_token => access_token.token,
57
- :uids => access_token.params["user_id"],
58
- :fields => @user_info_mapping.values.join(",")
59
- }
60
-
61
- response = access_token.get(@user_info_url, :params => params)
62
- if user_hash[:user_info] = JSON.parse(response.body)
63
- user_hash[:user_info] = user_hash[:user_info]["response"][0]
64
- # add full_name - useful if you do not store it in separate fields
65
- user_hash[:user_info]["full_name"] = [user_hash[:user_info]["first_name"], user_hash[:user_info]["last_name"]].join(" ")
66
- user_hash[:uid] = user_hash[:user_info]["uid"]
67
- end
68
- user_hash
69
- end
70
-
71
- def has_callback?
72
- true
73
- end
74
-
75
- # calculates and returns the url to which the user should be redirected,
76
- # to get authenticated at the external provider's site.
77
- def login_url(params,session)
78
- self.authorize_url({:authorize_url => @auth_path})
79
- end
80
-
81
- # tries to login the user from access token
82
- def process_callback(params,session)
83
- args = {}
84
- args.merge!({:code => params[:code]}) if params[:code]
85
- options = {
86
- :token_url => @token_path,
87
- :token_method => :post
88
- }
89
- return self.get_access_token(args, options)
90
- end
91
-
92
- end
93
- init
94
- end
95
-
96
- end
97
- end
98
- end
99
- end
100
- end
101
- end
@@ -1,98 +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 xing.com.
7
- # When included in the 'config.providers' option, it adds a new option, 'config.xing'.
8
- # Via this new option you can configure Xing specific settings like your app's key and secret.
9
- #
10
- # config.xing.key = <key>
11
- # config.xing.secret = <secret>
12
- # ...
13
- #
14
- module Xing
15
- def self.included(base)
16
- base.module_eval do
17
- class << self
18
- attr_reader :xing
19
-
20
- def merge_xing_defaults!
21
- @defaults.merge!(:@xing => XingClient)
22
- end
23
- end
24
- merge_xing_defaults!
25
- update!
26
- end
27
- end
28
-
29
- module XingClient
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
- :state
42
- attr_reader :access_token
43
-
44
- include Protocols::Oauth1
45
-
46
- # Override included get_consumer method to provide authorize_path
47
- def get_consumer
48
- ::OAuth::Consumer.new(@key, @secret, @configuration)
49
- end
50
-
51
- def init
52
- @configuration = {
53
- site: "https://api.xing.com/v1",
54
- authorize_path: '/authorize',
55
- request_token_path: '/request_token',
56
- access_token_path: '/access_token'
57
- }
58
- @user_info_path = "/users/me"
59
- end
60
-
61
- def get_user_hash(access_token)
62
- user_hash = {}
63
- response = access_token.get(@user_info_path)
64
- user_hash[:user_info] = JSON.parse(response.body)['users'].first
65
- user_hash[:uid] = user_hash[:user_info]['id'].to_s
66
- user_hash
67
- end
68
-
69
- def has_callback?
70
- true
71
- end
72
-
73
- # calculates and returns the url to which the user should be redirected,
74
- # to get authenticated at the external provider's site.
75
- def login_url(params,session)
76
- req_token = self.get_request_token
77
- session[:request_token] = req_token.token
78
- session[:request_token_secret] = req_token.secret
79
- self.authorize_url({:request_token => req_token.token, :request_token_secret => req_token.secret})
80
- end
81
-
82
- # tries to login the user from access token
83
- def process_callback(params, session)
84
- args = {}
85
- args.merge!({:oauth_verifier => params[:oauth_verifier], :request_token => session[:request_token], :request_token_secret => session[:request_token_secret]})
86
- args.merge!({:code => params[:code]}) if params[:code]
87
- return self.get_access_token(args)
88
- end
89
-
90
- end
91
- init
92
- end
93
- end
94
- end
95
- end
96
- end
97
- end
98
- end
@@ -1,5 +0,0 @@
1
- module Sorcery
2
- module TestHelpers
3
-
4
- end
5
- end