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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64c088c6e02a7eab994121ca4286c1c8781de98e
4
- data.tar.gz: d003d2b5b10efdf72085430bf4ceb2d34344b02f
3
+ metadata.gz: c733f127822efd64b509c325d9038b576f158fed
4
+ data.tar.gz: 6a7c59cfc1e3d736443a3c7e20e2270a1ba87699
5
5
  SHA512:
6
- metadata.gz: 53e16a72196c8d91f039a4f46ee3c3a0b73dcf8a1d4b1d3c83e02d47b4a0e3c161e0779afaee6cd254b3b413aa700f7869178c77750d918556b208500954a86a
7
- data.tar.gz: c3419bc56224d7b5375bef5ca25c9ead6408d033e5aad2c52d861b6ffa0f4b59a31add90f8dbba833e468dbccde695400085b9ed5e2598a09cfe7dc4b0d9e630
6
+ metadata.gz: 192f2d7789ea37d404e86fa5379841998f58bc6a59ce57bdfdd8aaf89dfa14008ee25a77eba5a513ec0acbf4efe07dc7693e7281c640101bc40bdd163f4d4127
7
+ data.tar.gz: eb3ca5bea7e5c15c58e5070bfc979e68f4ddcab297d61e66582fd86a2ae3ffc69996f8a8f7211f88e6db449ea3096e98ddab29755d852599bf4f2ce1989d890b
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
  ruby '2.2.2'
3
3
 
4
+ gem 'multi_json', '~>1.11.2'
4
5
  gem 'json', '~>1.5'
5
6
  gem 'warden', '~>1.0'
6
7
  gem 'oauth2', '~>0.5.2'
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/lib/#{m[1]}_spec.rb" }
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
@@ -1,6 +1,6 @@
1
1
  require 'warden'
2
2
  require 'oauth2'
3
- require 'json'
3
+ require 'multi_json'
4
4
 
5
5
  module Warden
6
6
  module Oauthed
@@ -8,19 +8,14 @@ module Warden
8
8
  end
9
9
 
10
10
  def ssl_options
11
- ca_file = "/usr/lib/ssl/certs/ca-certificates.crt"
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
- :ssl => ssl_options,
22
- :site => oauth_domain,
23
- :authorize_url => '/oauth/authorize')
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 '/api/v1/me' do |request|
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 = JSON.parse(resp)
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>)
@@ -2,8 +2,7 @@ module Warden
2
2
  module Oauthed
3
3
  module Oauth
4
4
  class User < Struct.new(:attribs, :token)
5
- ATTRIBUTES = %w[id full_name email].freeze
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] }
@@ -1,5 +1,5 @@
1
1
  module Warden
2
2
  module Oauthed
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
@@ -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'])
@@ -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', '~>1.5'
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.1
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-10 00:00:00.000000000 Z
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