warden-oauthed 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Guardfile +5 -5
- data/lib/warden-oauthed.rb +1 -1
- data/lib/warden-oauthed/proxy.rb +4 -9
- data/lib/warden-oauthed/strategy.rb +6 -2
- data/lib/warden-oauthed/user.rb +1 -2
- data/lib/warden-oauthed/version.rb +1 -1
- data/spec/oauth_spec.rb +4 -0
- data/warden-oauthed.gemspec +2 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c733f127822efd64b509c325d9038b576f158fed
|
4
|
+
data.tar.gz: 6a7c59cfc1e3d736443a3c7e20e2270a1ba87699
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 192f2d7789ea37d404e86fa5379841998f58bc6a59ce57bdfdd8aaf89dfa14008ee25a77eba5a513ec0acbf4efe07dc7693e7281c640101bc40bdd163f4d4127
|
7
|
+
data.tar.gz: eb3ca5bea7e5c15c58e5070bfc979e68f4ddcab297d61e66582fd86a2ae3ffc69996f8a8f7211f88e6db449ea3096e98ddab29755d852599bf4f2ce1989d890b
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
group :red_green_refactor, halt_on_fail: true do
|
2
2
|
guard :rspec, cmd: "bundle exec rspec", failed_mode: 'focus' do
|
3
3
|
watch(%r{^spec/.+_spec\.rb$})
|
4
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec
|
5
|
-
end
|
6
|
-
guard :rubocop, all_on_start: false do
|
7
|
-
watch(/.+\.rb$/)
|
8
|
-
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
4
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
9
5
|
end
|
6
|
+
# guard :rubocop, all_on_start: false do
|
7
|
+
# watch(/.+\.rb$/)
|
8
|
+
# watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
9
|
+
# end
|
10
10
|
end
|
data/lib/warden-oauthed.rb
CHANGED
data/lib/warden-oauthed/proxy.rb
CHANGED
@@ -8,19 +8,14 @@ module Warden
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def ssl_options
|
11
|
-
|
12
|
-
if File.exists?(ca_file)
|
13
|
-
{ :ca_file => ca_file }
|
14
|
-
else
|
15
|
-
{ :ca_file => ''}
|
16
|
-
end
|
11
|
+
{ version: :TLSv1 }
|
17
12
|
end
|
18
13
|
|
19
14
|
def client
|
20
15
|
@client ||= OAuth2::Client.new(@client_id, @secret,
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
ssl: ssl_options,
|
17
|
+
site: oauth_domain,
|
18
|
+
authorize_url: '/oauth/authorize')
|
24
19
|
end
|
25
20
|
|
26
21
|
def api_for(code)
|
@@ -5,16 +5,20 @@ Warden::Strategies.add(:oauthed) do
|
|
5
5
|
@params ||= Rack::Utils.parse_query(request.query_string)
|
6
6
|
end
|
7
7
|
|
8
|
+
def api_url
|
9
|
+
ENV['API_BASE_URL'] || '/api/v1'
|
10
|
+
end
|
11
|
+
|
8
12
|
def authenticate!
|
9
13
|
if params['code']
|
10
14
|
begin
|
11
15
|
api = api_for(params['code'])
|
12
16
|
|
13
|
-
resp = api.get
|
17
|
+
resp = api.get "#{api_url}/me" do |request|
|
14
18
|
request.params['access_token'] = api.token
|
15
19
|
end.body
|
16
20
|
|
17
|
-
user =
|
21
|
+
user = MultiJson.load(resp)
|
18
22
|
success!(Warden::Oauthed::Oauth::User.new(user['user'], api.token))
|
19
23
|
rescue OAuth2::Error
|
20
24
|
%(<p>Outdated ?code=#{params['code']}:</p><p>#{$!}</p><p><a href="/auth/oauthed">Retry</a></p>)
|
data/lib/warden-oauthed/user.rb
CHANGED
@@ -2,8 +2,7 @@ module Warden
|
|
2
2
|
module Oauthed
|
3
3
|
module Oauth
|
4
4
|
class User < Struct.new(:attribs, :token)
|
5
|
-
ATTRIBUTES =
|
6
|
-
|
5
|
+
ATTRIBUTES = (ENV['USER_ATTRIBUTES'] || 'id email').split(/\s/).freeze
|
7
6
|
|
8
7
|
ATTRIBUTES.each do |name|
|
9
8
|
define_method(name) { attribs[name] }
|
data/spec/oauth_spec.rb
CHANGED
@@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Warden::Oauthed' do
|
4
4
|
it 'requesting an url that requires authentication redirects to github' do
|
5
|
+
ENV['OAUTH_BASE_URL'] = 'http://localhost:3000'
|
6
|
+
ENV['APPLICATION_SCOPES_REQUESTED'] = 'public'
|
7
|
+
ENV['APPLICATION_CLIENT_ID'] = 'fd6df6f74658a9202d401aaba38223a7f79e7572926ce845e5268f5171e5b2d5'
|
8
|
+
ENV['APPLICATION_CLIENT_SECRET'] = 'afee0e20322e5d73dff82f29baf5989afd3422557056129aad29d974e56df677'
|
5
9
|
response = get '/'
|
6
10
|
|
7
11
|
uri = Addressable::URI.parse(response.headers['Location'])
|
data/warden-oauthed.gemspec
CHANGED
@@ -12,7 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.license = 'MIT'
|
13
13
|
s.description = s.summary
|
14
14
|
|
15
|
-
s.add_dependency 'json',
|
15
|
+
s.add_dependency 'json', '~>1.5'
|
16
|
+
s.add_dependency 'multi_json', '~>1.11.2'
|
16
17
|
s.add_dependency 'warden', '~>1.0'
|
17
18
|
s.add_dependency 'oauth2', '~>0.5.2'
|
18
19
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warden-oauthed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Jaress
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-10-
|
12
|
+
date: 2015-10-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.5'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: multi_json
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.11.2
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.11.2
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: warden
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|