warden-github 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 224cc683e53b8c9473f283a08b8e1fe055c5731f
4
- data.tar.gz: c7d9b17f19afd74236dbaeb9e14a1598e2bd3761
3
+ metadata.gz: 19f7ba1fd04d8c9480a20834ce998b07685f7bcf
4
+ data.tar.gz: c1dc58f92e7bb9682f17e29598b879926ddccc32
5
5
  SHA512:
6
- metadata.gz: 3bc465c114cce993843b36b8c9d5273ae3bd6084babb0ac7f04d79cdaa15c45dda22c96b5246b7e91f1a6d818923acff2dfc8aa7bfa07764faf62ac48585eb6f
7
- data.tar.gz: ea076c77866bc95683a747c63493ce020dd3a4c98349c7f27de81d6b8c651255961bf87df30fd539cc5f846f361ea17f4ee40e851269e9fa896d22ffa83887d6
6
+ metadata.gz: 9a0926d904ffc5f765d138c38cb8fdf9bf95b8ef8514111683724d550184802a867906d7e2a0a20bcd9297c791d6c51f5737bc33d8817c81bffb859df83fc357
7
+ data.tar.gz: 26e92ebfaedef533d2610b2a8ba91b76d7a4265ec5b8f978a3c624bf4e6199a0f0ccb5b53e489d32d1c6e2b9668ed6fe299b1fc585b51cdb66d43a35d1cacb5b
data/README.md CHANGED
@@ -53,9 +53,14 @@ use Warden::Manager do |config|
53
53
  :client_secret => 'barfoo',
54
54
  :scope => 'user,repo',
55
55
  :redirect_uri => '/admin/oauth/callback' }
56
+
57
+ config.serialize_from_session { |key| Warden::GitHub::Verifier.load(key) }
58
+ config.serialize_into_session { |user| Warden::GitHub::Verifier.dump(user) }
56
59
  end
57
60
  ```
58
61
 
62
+ The two serialization methods store the API token in the session securely via the `WARDEN_GITHUB_VERIFIER_SECRET` environmental variable.
63
+
59
64
  ### Parameters
60
65
 
61
66
  The config parameters and their defaults are listed below.
data/config.ru CHANGED
@@ -1,19 +1,6 @@
1
1
  ENV['RACK_ENV'] ||= 'development'
2
2
 
3
- begin
4
- require File.expand_path('../.bundle/environment', __FILE__)
5
- rescue LoadError
6
- require "rubygems"
7
- require "bundler"
8
- Bundler.setup
9
- end
10
-
11
- begin
12
- require 'debugger'
13
- rescue LoadError
14
- require 'ruby-debug'
15
- end
16
-
3
+ require "bundler/setup"
17
4
  require 'warden/github'
18
5
 
19
6
  if ENV['MULTI_SCOPE_APP']
@@ -14,6 +14,8 @@ module Example
14
14
  config.failure_app = BadAuthentication
15
15
  config.default_strategies :github
16
16
  config.scope_defaults :default, :config => GITHUB_CONFIG
17
+ config.serialize_from_session { |key| Warden::GitHub::Verifier.load(key) }
18
+ config.serialize_into_session { |user| Warden::GitHub::Verifier.dump(user) }
17
19
  end
18
20
 
19
21
  get '/' do
data/lib/warden/github.rb CHANGED
@@ -7,5 +7,7 @@ require 'warden/github/strategy'
7
7
  require 'warden/github/hook'
8
8
  require 'warden/github/config'
9
9
  require 'warden/github/membership_cache'
10
+ require 'warden/github/verifier'
10
11
 
12
+ require 'active_support/message_verifier'
11
13
  require 'securerandom'
@@ -0,0 +1,38 @@
1
+ module Warden
2
+ module GitHub
3
+ class Verifier
4
+ def self.dump(user)
5
+ new.serialize(user)
6
+ end
7
+
8
+ def self.load(key)
9
+ new.deserialize(key)
10
+ end
11
+
12
+ def serialize(user)
13
+ cookie_verifier.generate(user.marshal_dump)
14
+ end
15
+
16
+ def deserialize(key)
17
+ User.new.tap do |u|
18
+ u.marshal_load(cookie_verifier.verify(key))
19
+ end
20
+ rescue ::ActiveSupport::MessageVerifier::InvalidSignature
21
+ nil
22
+ end
23
+
24
+ def verifier_key
25
+ self.class.verifier_key
26
+ end
27
+
28
+ private
29
+ def self.verifier_key
30
+ @verifier_key ||= ENV['WARDEN_GITHUB_VERIFIER_SECRET'] || SecureRandom.hex
31
+ end
32
+
33
+ def cookie_verifier
34
+ @cookie_verifier ||= ::ActiveSupport::MessageVerifier.new(verifier_key, serializer: JSON)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  module Warden
2
2
  module GitHub
3
- VERSION = "1.0.3"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ describe Warden::GitHub::MembershipCache do
7
7
 
8
8
  describe '#fetch_membership' do
9
9
  it 'returns false by default' do
10
- cache.fetch_membership('foo', 'bar').should be_false
10
+ cache.fetch_membership('foo', 'bar').should be_falsey
11
11
  end
12
12
 
13
13
  context 'when cache valid' do
@@ -17,7 +17,7 @@ describe Warden::GitHub::MembershipCache do
17
17
  end
18
18
 
19
19
  it 'returns true' do
20
- cache.fetch_membership('foo', 'bar').should be_true
20
+ cache.fetch_membership('foo', 'bar').should be_truthy
21
21
  end
22
22
 
23
23
  it 'does not invoke the block' do
@@ -34,7 +34,7 @@ describe Warden::GitHub::MembershipCache do
34
34
 
35
35
  context 'when no block given' do
36
36
  it 'returns false' do
37
- cache.fetch_membership('foo', 'bar').should be_false
37
+ cache.fetch_membership('foo', 'bar').should be_falsey
38
38
  end
39
39
  end
40
40
 
@@ -51,12 +51,12 @@ describe Warden::GitHub::MembershipCache do
51
51
 
52
52
  it 'caches the value when block returns true' do
53
53
  cache.fetch_membership('foo', 'bar') { true }
54
- cache.fetch_membership('foo', 'bar').should be_true
54
+ cache.fetch_membership('foo', 'bar').should be_truthy
55
55
  end
56
56
 
57
57
  it 'does not cache the value when block returns false' do
58
58
  cache.fetch_membership('foo', 'bar') { false }
59
- cache.fetch_membership('foo', 'bar').should be_false
59
+ cache.fetch_membership('foo', 'bar').should be_falsey
60
60
  end
61
61
  end
62
62
  end
@@ -50,14 +50,14 @@ describe Warden::GitHub::User do
50
50
  context 'when user is not member' do
51
51
  it 'returns false' do
52
52
  stub_api(user, method, ['rails', user.login], false)
53
- user.send(method, 'rails').should be_false
53
+ user.send(method, 'rails').should be_falsey
54
54
  end
55
55
  end
56
56
 
57
57
  context 'when user is member' do
58
58
  it 'returns true' do
59
59
  stub_api(user, method, ['rails', user.login], true)
60
- user.send(method, 'rails').should be_true
60
+ user.send(method, 'rails').should be_truthy
61
61
  end
62
62
  end
63
63
  end
@@ -14,8 +14,9 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "warden-github"
16
16
 
17
- s.add_dependency "warden", ">1.0"
18
- s.add_dependency "octokit", ">2.1.0"
17
+ s.add_dependency "warden", ">1.0"
18
+ s.add_dependency "octokit", ">2.1.0"
19
+ s.add_dependency "activesupport", ">3.0"
19
20
 
20
21
  s.add_development_dependency "rack", "~>1.4.1"
21
22
  s.add_development_dependency "rake"
@@ -24,7 +25,7 @@ Gem::Specification.new do |s|
24
25
  s.add_development_dependency "webmock", "~>1.9"
25
26
  s.add_development_dependency "sinatra"
26
27
  s.add_development_dependency "shotgun"
27
- s.add_development_dependency "addressable", "~>2.2.0"
28
+ s.add_development_dependency "addressable", ">2.2.0"
28
29
  s.add_development_dependency "rack-test", "~>0.5.3"
29
30
  s.add_development_dependency "yajl-ruby"
30
31
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warden-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Corey Donohoe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-13 00:00:00.000000000 Z
11
+ date: 2015-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: warden
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rack
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -140,14 +154,14 @@ dependencies:
140
154
  name: addressable
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - "~>"
157
+ - - ">"
144
158
  - !ruby/object:Gem::Version
145
159
  version: 2.2.0
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - "~>"
164
+ - - ">"
151
165
  - !ruby/object:Gem::Version
152
166
  version: 2.2.0
153
167
  - !ruby/object:Gem::Dependency
@@ -204,6 +218,7 @@ files:
204
218
  - lib/warden/github/oauth.rb
205
219
  - lib/warden/github/strategy.rb
206
220
  - lib/warden/github/user.rb
221
+ - lib/warden/github/verifier.rb
207
222
  - lib/warden/github/version.rb
208
223
  - spec/fixtures/user.json
209
224
  - spec/integration/oauth_spec.rb