foyer 0.2.2 → 0.3.1

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: af5cb236dc4e724cfcc0e93c0b595257dbd3209d
4
- data.tar.gz: 14bf2bfdc8a8c2a7cc0f3fc3f7024a3d312b2da3
3
+ metadata.gz: 57d0883283b4f625d72d8ce225b286601a4f30ef
4
+ data.tar.gz: 3a6aaf54a13c2f79623033a6e7458568599ac659
5
5
  SHA512:
6
- metadata.gz: c40bfe2653f1a3d675be903bb880ddae30d1cd3bd707c0f6c101c294ddaeac2d1e26a4106de5c7690a303e2cc11e689e4bf4347f0a2267a6a2892f427e8fdaee
7
- data.tar.gz: 304fcf02a5b52432cd7bd9b64273586e1570f9b1c01f94f69031c87e8dc087ea573e1188b25f6a828089fd45a244e6d98f8e356918774e4fcf84783c11204b5a
6
+ metadata.gz: 32ca88d2cd4a48b234ce4316ca7b5acafc4d329223facb668aaaf01c928e7c58b0408e6abdaf1dd571b740be0c2a52ebd5937cacbb366734b0d926b02e8c9880
7
+ data.tar.gz: a12db3dd41cd7b8978f929a35c016bec424ec71a7f6f1ab1ef728a6e846d8183b99d43cbaac98ed703f5ee64ed9d9ae35136f5a359f909c43189c669f6641b27
data/.rubocop.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  AllCops:
2
- RunRailsCops: true
3
2
  Exclude:
4
3
  # Rubocop's default
5
4
  - 'vendor/**/*'
@@ -29,6 +28,9 @@ AllCops:
29
28
  # Add your exclude files specific to this project here
30
29
  - 'spec/dummy/config/initializers/secret_token.rb'
31
30
 
31
+ Rails:
32
+ Enabled: true
33
+
32
34
  Style/AlignParameters:
33
35
  Enabled: true
34
36
  EnforcedStyle: with_fixed_indentation
@@ -36,14 +38,20 @@ Style/AlignParameters:
36
38
  Style/Documentation:
37
39
  Enabled: false
38
40
 
41
+ Style/FrozenStringLiteralComment:
42
+ Enabled: false
43
+
39
44
  # If the project still supporting ruby 1.8, uncomment the following lines to force Rubocop
40
45
  # to use old hash_rockets syntax, if left commented, Rubocop will force the newer ruby19 syntax
41
46
  # Style/HashSyntax:
42
47
  # EnforcedStyle: hash_rockets
43
48
 
44
- Style/SingleSpaceBeforeFirstArg:
49
+ Style/SpaceBeforeFirstArg:
45
50
  Enabled: false
46
51
 
52
+ Style/SignalException:
53
+ EnforcedStyle: semantic
54
+
47
55
  ##################### Metrics ##################################
48
56
 
49
57
  Metrics/LineLength:
data/.travis.yml CHANGED
@@ -3,9 +3,8 @@ language: ruby
3
3
  cache:
4
4
  - bundler
5
5
  rvm:
6
- - 2.1.4
6
+ - 2.3.0
7
+ - 2.1.8
7
8
  - 2.0.0
8
- - 1.9.3
9
- - jruby-19mode
10
9
  before_script:
11
10
  - bundle exec rubocop -D
data/foyer.gemspec CHANGED
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.5'
24
24
  spec.add_development_dependency 'rake'
25
- spec.add_development_dependency 'rspec-rails', '~> 3.0.0.beta'
25
+ spec.add_development_dependency 'rspec-rails', '~> 3.4'
26
26
  spec.add_development_dependency 'rubocop'
27
27
  end
data/lib/foyer.rb CHANGED
@@ -24,6 +24,10 @@ module Foyer
24
24
  autoload :Helpers, 'foyer/controller/helpers'
25
25
  end
26
26
 
27
+ module API
28
+ autoload :Helpers, 'foyer/api/helpers'
29
+ end
30
+
27
31
  module Grape
28
32
  autoload :Helpers, 'foyer/grape/helpers'
29
33
  end
@@ -0,0 +1,29 @@
1
+ module Foyer
2
+ module API
3
+ module Helpers
4
+ extend ActiveSupport::Concern
5
+
6
+ protected
7
+
8
+ def user_signed_in?
9
+ current_user.present?
10
+ end
11
+
12
+ def current_user
13
+ return nil unless request.authorization.to_s =~ /^Bearer (.*)/m
14
+ @current_user ||= Foyer.token_finder.call(Regexp.last_match[1])
15
+ end
16
+
17
+ def authenticate_user!
18
+ head :unauthorized unless user_signed_in?
19
+ end
20
+
21
+ module ClassMethods
22
+ def set_token_finder(&blk) # rubocop:disable Style/AccessorMethodName
23
+ fail ':token_finder must accept 1 argument (token)' unless blk.arity == 1
24
+ Foyer.token_finder = blk
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -2,13 +2,10 @@ module Foyer
2
2
  module Grape
3
3
  module Helpers
4
4
  extend ActiveSupport::Concern
5
+ include Foyer::API::Helpers
5
6
 
6
7
  protected
7
8
 
8
- def user_signed_in?
9
- current_user.present?
10
- end
11
-
12
9
  def current_user
13
10
  return nil unless headers['Authorization'] =~ /^Bearer (.*)/m
14
11
  @current_user ||= Foyer.token_finder.call(Regexp.last_match[1])
@@ -17,13 +14,6 @@ module Foyer
17
14
  def authenticate_user!
18
15
  error!('Unauthorized', 401) unless user_signed_in?
19
16
  end
20
-
21
- module ClassMethods
22
- def set_token_finder(&blk) # rubocop:disable Style/AccessorMethodName
23
- fail ':token_finder must accept 1 argument (token)' unless blk.arity == 1
24
- Foyer.token_finder = blk
25
- end
26
- end
27
17
  end
28
18
  end
29
19
  end
data/lib/foyer/rails.rb CHANGED
@@ -6,7 +6,8 @@ module ActionDispatch
6
6
  def authenticate(guard = nil)
7
7
  constraint = lambda do |request|
8
8
  user_id = request.env['rack.session'][Foyer.session_key].try(:with_indifferent_access).try(:[], :id)
9
- guard.nil? ? true : guard.call(Foyer.user_finder.call(user_id)) if user_id
9
+ break unless user_id
10
+ guard.nil? ? true : guard.call(Foyer.user_finder.call(user_id))
10
11
  end
11
12
 
12
13
  constraints(constraint) do
data/lib/foyer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Foyer
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.1'.freeze
3
3
  end
@@ -15,7 +15,7 @@ describe AuthenticatedController, type: :controller do
15
15
 
16
16
  response.location.split('?').last.tap do |query_string|
17
17
  expect(query_string.split('=').first).to eq('origin')
18
- expect(query_string.split('=').last).to eq(CGI.escape '/authenticated')
18
+ expect(query_string.split('=').last).to eq(CGI.escape('/authenticated'))
19
19
  end
20
20
  end
21
21
  end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foyer::API::Helpers do
4
+ class IncludesFoyerAPIHelpers
5
+ def request
6
+ @request ||= Struct.new(:authorization).new('Bearer _')
7
+ end
8
+
9
+ include Foyer::API::Helpers
10
+ end
11
+
12
+ subject { IncludesFoyerAPIHelpers.new }
13
+
14
+ describe '.set_token_finder' do
15
+ it 'sets the :token_finder configuration to the provided block' do
16
+ expect do
17
+ subject.class_eval do
18
+ set_token_finder do |token|
19
+ token
20
+ end
21
+ end
22
+ end.to change(Foyer, :token_finder)
23
+ end
24
+ end
25
+
26
+ describe '#current_user' do
27
+ it 'calls the token_finder method' do
28
+ @called = false
29
+ Foyer.token_finder = ->(_) { @called = true }
30
+
31
+ subject.send :current_user
32
+
33
+ expect(@called).to eq true
34
+ end
35
+ end
36
+ end
@@ -8,14 +8,14 @@ module Foyer
8
8
  end
9
9
 
10
10
  it 'defaults to root path' do
11
- expect(controller.send :after_sign_in_path).to eq('/')
11
+ expect(controller.send(:after_sign_in_path)).to eq('/')
12
12
  end
13
13
 
14
14
  it 'returns omniauth.origin if available' do
15
15
  origin = '/some_path'
16
16
  @request.env['omniauth.origin'] = origin
17
17
 
18
- expect(controller.send :after_sign_in_path).to eq(origin)
18
+ expect(controller.send(:after_sign_in_path)).to eq(origin)
19
19
  end
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foyer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Nochlin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-01 00:00:00.000000000 Z
11
+ date: 2016-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 3.0.0.beta
61
+ version: '3.4'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 3.0.0.beta
68
+ version: '3.4'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +97,7 @@ files:
97
97
  - Rakefile
98
98
  - foyer.gemspec
99
99
  - lib/foyer.rb
100
+ - lib/foyer/api/helpers.rb
100
101
  - lib/foyer/controller/helpers.rb
101
102
  - lib/foyer/engine.rb
102
103
  - lib/foyer/grape/helpers.rb
@@ -139,6 +140,7 @@ files:
139
140
  - spec/dummy/public/422.html
140
141
  - spec/dummy/public/500.html
141
142
  - spec/dummy/public/favicon.ico
143
+ - spec/foyer/api/helpers_spec.rb
142
144
  - spec/foyer/controller/helpers_spec.rb
143
145
  - spec/foyer/grape/helpers_spec.rb
144
146
  - spec/foyer/omniauth_callbacks_controller_spec.rb
@@ -164,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
166
  version: '0'
165
167
  requirements: []
166
168
  rubyforge_project:
167
- rubygems_version: 2.2.5
169
+ rubygems_version: 2.5.1
168
170
  signing_key:
169
171
  specification_version: 4
170
172
  summary: Authentication layer for OmniAuth
@@ -204,9 +206,9 @@ test_files:
204
206
  - spec/dummy/public/422.html
205
207
  - spec/dummy/public/500.html
206
208
  - spec/dummy/public/favicon.ico
209
+ - spec/foyer/api/helpers_spec.rb
207
210
  - spec/foyer/controller/helpers_spec.rb
208
211
  - spec/foyer/grape/helpers_spec.rb
209
212
  - spec/foyer/omniauth_callbacks_controller_spec.rb
210
213
  - spec/integration/authenticate_via_route_constraint_spec.rb
211
214
  - spec/spec_helper.rb
212
- has_rdoc: