foyer 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
 - data/lib/foyer.rb +7 -0
 - data/lib/foyer/controller/helpers.rb +3 -2
 - data/lib/foyer/grape/helpers.rb +30 -0
 - data/lib/foyer/version.rb +1 -1
 - data/spec/foyer/grape/helpers_spec.rb +36 -0
 - metadata +10 -7
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,15 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
              data.tar.gz: !binary |-
         
     | 
| 
       6 
     | 
    
         
            -
                YjBkOWM3NjNmYTk0MmVkZWRmMzkxOGU5YThmODMxYjcyN2M2YTZiYQ==
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 682800c810ac3c955473143f0bec308908390fcf
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: b871b220cc2c46069cd0070f60f88a70d0d2bf30
         
     | 
| 
       7 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       8 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                Yjg1MGFhNDBlZDdjYjE4MGFlOTMxNDlkMDdjMDY4OWVmMzA0N2MxODFmYWUy
         
     | 
| 
       11 
     | 
    
         
            -
                ZTVlZWJiNjM5MDFjYzVkZGZmODBjZjAxNmQzOTcyNWZjMTAxNWI=
         
     | 
| 
       12 
     | 
    
         
            -
              data.tar.gz: !binary |-
         
     | 
| 
       13 
     | 
    
         
            -
                ZGFiNmEyMTliNDBkNjRlMjllYzA2ZTVmMmE3OWJlNDRiODEwNmMwZjVmNTM1
         
     | 
| 
       14 
     | 
    
         
            -
                ODdhNzc3MjRlYjRkZWIzYjE1NzNmZjQ5ZTlhZmU5MWI3MDlhOWYxOWY0Y2M5
         
     | 
| 
       15 
     | 
    
         
            -
                OGRlMTQzODg4ZjBiNmEwYmFjMTI2YjljY2ZkNmM0MzNhN2ZmM2M=
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 6fcf0ca948b532f9ae84fa68f7b277691790142da2ec1170ff12785bd8a0e8f7718d0b3ae60e4b33a0b70068b1cde4890768f2f40537caafabac0b8a48f70805
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 81473a970e91d87620a36a8aee2cfc6842f0921ecaf6aac905bb8686aba9b0522f83a11131e439c716fc4f4cbaeb8dc32852d3e3436e27f4120bc77dc94d0aa3
         
     | 
    
        data/lib/foyer.rb
    CHANGED
    
    | 
         @@ -12,10 +12,17 @@ module Foyer 
     | 
|
| 
       12 
12 
     | 
    
         
             
              mattr_accessor :user_finder
         
     | 
| 
       13 
13 
     | 
    
         
             
              @@user_finder = lambda { |_| raise 'Override this method' }
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
      
 15 
     | 
    
         
            +
              mattr_accessor :token_finder
         
     | 
| 
      
 16 
     | 
    
         
            +
              @@token_finder = lambda { |_| raise 'Override this method' }
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
       15 
18 
     | 
    
         
             
              module Controller
         
     | 
| 
       16 
19 
     | 
    
         
             
                autoload :Helpers, 'foyer/controller/helpers'
         
     | 
| 
       17 
20 
     | 
    
         
             
              end
         
     | 
| 
       18 
21 
     | 
    
         | 
| 
      
 22 
     | 
    
         
            +
              module Grape
         
     | 
| 
      
 23 
     | 
    
         
            +
                autoload :Helpers, 'foyer/grape/helpers'
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
       19 
26 
     | 
    
         
             
              autoload :OmniauthCallbacksController, 'foyer/omniauth_callbacks_controller'
         
     | 
| 
       20 
27 
     | 
    
         | 
| 
       21 
28 
     | 
    
         
             
              autoload :TestHelpers, 'foyer/test_helpers'
         
     | 
| 
         @@ -13,7 +13,7 @@ module Foyer 
     | 
|
| 
       13 
13 
     | 
    
         
             
                      id: user.id,
         
     | 
| 
       14 
14 
     | 
    
         
             
                      current_sign_in_at: Time.now,
         
     | 
| 
       15 
15 
     | 
    
         
             
                      current_sign_in_ip: request.ip,
         
     | 
| 
       16 
     | 
    
         
            -
                    }
         
     | 
| 
      
 16 
     | 
    
         
            +
                    }.with_indifferent_access
         
     | 
| 
       17 
17 
     | 
    
         
             
                  end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                  def sign_out
         
     | 
| 
         @@ -30,7 +30,8 @@ module Foyer 
     | 
|
| 
       30 
30 
     | 
    
         
             
                  end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
                  def user_session
         
     | 
| 
       33 
     | 
    
         
            -
                    session[Foyer.session_key]||= {}
         
     | 
| 
      
 33 
     | 
    
         
            +
                    session[Foyer.session_key] ||= {}
         
     | 
| 
      
 34 
     | 
    
         
            +
                    session[Foyer.session_key] = session[Foyer.session_key].with_indifferent_access
         
     | 
| 
       34 
35 
     | 
    
         
             
                    session[Foyer.session_key]
         
     | 
| 
       35 
36 
     | 
    
         
             
                  end
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Foyer
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Grape
         
     | 
| 
      
 3 
     | 
    
         
            +
                module Helpers
         
     | 
| 
      
 4 
     | 
    
         
            +
                  extend ActiveSupport::Concern
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                  protected
         
     | 
| 
      
 7 
     | 
    
         
            +
                  def user_signed_in?
         
     | 
| 
      
 8 
     | 
    
         
            +
                    current_user.present?
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  def current_user
         
     | 
| 
      
 12 
     | 
    
         
            +
                    return nil unless headers['Authorization'] =~ /^Bearer (.*)/m
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @current_user ||= Foyer.token_finder.call($1)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  def authenticate_user!
         
     | 
| 
      
 17 
     | 
    
         
            +
                    error!('Unauthorized', 401) unless user_signed_in?
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  module ClassMethods
         
     | 
| 
      
 21 
     | 
    
         
            +
                    def set_token_finder(&blk)
         
     | 
| 
      
 22 
     | 
    
         
            +
                      if blk.arity != 1
         
     | 
| 
      
 23 
     | 
    
         
            +
                        raise ":token_finder must accept 1 argument (token)"
         
     | 
| 
      
 24 
     | 
    
         
            +
                      end
         
     | 
| 
      
 25 
     | 
    
         
            +
                      Foyer.token_finder = blk
         
     | 
| 
      
 26 
     | 
    
         
            +
                    end
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/foyer/version.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,36 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Foyer::Grape::Helpers do
         
     | 
| 
      
 4 
     | 
    
         
            +
              class IncludesFoyerGrapeHelpers
         
     | 
| 
      
 5 
     | 
    
         
            +
                def headers
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @headers ||= { 'Authorization' => 'Bearer _' }
         
     | 
| 
      
 7 
     | 
    
         
            +
                end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                include Foyer::Grape::Helpers
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              subject { IncludesFoyerGrapeHelpers.new }
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              describe ".set_token_finder" do
         
     | 
| 
      
 15 
     | 
    
         
            +
                it "sets the :token_finder configuration to the provided block" do
         
     | 
| 
      
 16 
     | 
    
         
            +
                  expect {
         
     | 
| 
      
 17 
     | 
    
         
            +
                    subject.class_eval do
         
     | 
| 
      
 18 
     | 
    
         
            +
                      set_token_finder do |token|
         
     | 
| 
      
 19 
     | 
    
         
            +
                        token
         
     | 
| 
      
 20 
     | 
    
         
            +
                      end
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
                  }.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 = lambda { |_| @called = true }
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  subject.send :current_user
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  expect(@called).to eq true
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
            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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Jason Nochlin
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2014- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-07-09 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     | 
| 
         @@ -42,14 +42,14 @@ dependencies: 
     | 
|
| 
       42 
42 
     | 
    
         
             
              name: rake
         
     | 
| 
       43 
43 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       44 
44 
     | 
    
         
             
                requirements:
         
     | 
| 
       45 
     | 
    
         
            -
                - -  
     | 
| 
      
 45 
     | 
    
         
            +
                - - '>='
         
     | 
| 
       46 
46 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       47 
47 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       48 
48 
     | 
    
         
             
              type: :development
         
     | 
| 
       49 
49 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       50 
50 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       51 
51 
     | 
    
         
             
                requirements:
         
     | 
| 
       52 
     | 
    
         
            -
                - -  
     | 
| 
      
 52 
     | 
    
         
            +
                - - '>='
         
     | 
| 
       53 
53 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       54 
54 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       55 
55 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
         @@ -83,6 +83,7 @@ files: 
     | 
|
| 
       83 
83 
     | 
    
         
             
            - lib/foyer.rb
         
     | 
| 
       84 
84 
     | 
    
         
             
            - lib/foyer/controller/helpers.rb
         
     | 
| 
       85 
85 
     | 
    
         
             
            - lib/foyer/engine.rb
         
     | 
| 
      
 86 
     | 
    
         
            +
            - lib/foyer/grape/helpers.rb
         
     | 
| 
       86 
87 
     | 
    
         
             
            - lib/foyer/omniauth_callbacks_controller.rb
         
     | 
| 
       87 
88 
     | 
    
         
             
            - lib/foyer/rails.rb
         
     | 
| 
       88 
89 
     | 
    
         
             
            - lib/foyer/test_helpers.rb
         
     | 
| 
         @@ -123,6 +124,7 @@ files: 
     | 
|
| 
       123 
124 
     | 
    
         
             
            - spec/dummy/public/500.html
         
     | 
| 
       124 
125 
     | 
    
         
             
            - spec/dummy/public/favicon.ico
         
     | 
| 
       125 
126 
     | 
    
         
             
            - spec/foyer/controller/helpers_spec.rb
         
     | 
| 
      
 127 
     | 
    
         
            +
            - spec/foyer/grape/helpers_spec.rb
         
     | 
| 
       126 
128 
     | 
    
         
             
            - spec/foyer/omniauth_callbacks_controller_spec.rb
         
     | 
| 
       127 
129 
     | 
    
         
             
            - spec/integration/authenticate_via_route_constraint_spec.rb
         
     | 
| 
       128 
130 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
         @@ -136,17 +138,17 @@ require_paths: 
     | 
|
| 
       136 
138 
     | 
    
         
             
            - lib
         
     | 
| 
       137 
139 
     | 
    
         
             
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       138 
140 
     | 
    
         
             
              requirements:
         
     | 
| 
       139 
     | 
    
         
            -
              - -  
     | 
| 
      
 141 
     | 
    
         
            +
              - - '>='
         
     | 
| 
       140 
142 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       141 
143 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       142 
144 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       143 
145 
     | 
    
         
             
              requirements:
         
     | 
| 
       144 
     | 
    
         
            -
              - -  
     | 
| 
      
 146 
     | 
    
         
            +
              - - '>='
         
     | 
| 
       145 
147 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       146 
148 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       147 
149 
     | 
    
         
             
            requirements: []
         
     | 
| 
       148 
150 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       149 
     | 
    
         
            -
            rubygems_version: 2.2. 
     | 
| 
      
 151 
     | 
    
         
            +
            rubygems_version: 2.2.2
         
     | 
| 
       150 
152 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       151 
153 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       152 
154 
     | 
    
         
             
            summary: Authentication layer for OmniAuth
         
     | 
| 
         @@ -187,6 +189,7 @@ test_files: 
     | 
|
| 
       187 
189 
     | 
    
         
             
            - spec/dummy/public/500.html
         
     | 
| 
       188 
190 
     | 
    
         
             
            - spec/dummy/public/favicon.ico
         
     | 
| 
       189 
191 
     | 
    
         
             
            - spec/foyer/controller/helpers_spec.rb
         
     | 
| 
      
 192 
     | 
    
         
            +
            - spec/foyer/grape/helpers_spec.rb
         
     | 
| 
       190 
193 
     | 
    
         
             
            - spec/foyer/omniauth_callbacks_controller_spec.rb
         
     | 
| 
       191 
194 
     | 
    
         
             
            - spec/integration/authenticate_via_route_constraint_spec.rb
         
     | 
| 
       192 
195 
     | 
    
         
             
            - spec/spec_helper.rb
         
     |