softwear-lib 1.5.6 → 1.5.8
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
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4f0b0ffdf353b1125791532b04b4c69178f3848d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: b5ffb662dafdbd0ced2e2b3fda77c68314ed4a9e
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 51397655427dfd487c7690028a486f73e2b35bd4a5fa4bfd7a92b02a3b5f1cfe651d63d26238c4f5d0e5f3620e263264d8535abc8eb6f2bf9678921354fda310
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 536a85856023e46c1897ba453764710d257cc940beb5923b6510c1f3ff9ffaf40ab7c605443a469f927c9b3f4d0c6c25720f6ca64a43f537e16a3d36d2447a65
         
     | 
| 
         @@ -0,0 +1,56 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Softwear
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Auth
         
     | 
| 
      
 3 
     | 
    
         
            +
                module TokenAuthentication
         
     | 
| 
      
 4 
     | 
    
         
            +
                  extend ActiveSupport::Concern
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                  included do
         
     | 
| 
      
 7 
     | 
    
         
            +
                    cattr_accessor :user_class
         
     | 
| 
      
 8 
     | 
    
         
            +
                    cattr_accessor :token_auth_options
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  def token_authenticate_user!
         
     | 
| 
      
 12 
     | 
    
         
            +
                    user_class = self.class.user_class || base_class.user_class || User
         
     | 
| 
      
 13 
     | 
    
         
            +
                    options    = (self.class.token_auth_options || base_class.token_auth_options || {}).with_indifferent_access
         
     | 
| 
      
 14 
     | 
    
         
            +
                    params_options  = (options[:params]  || {}).with_indifferent_access
         
     | 
| 
      
 15 
     | 
    
         
            +
                    headers_options = (options[:headers] || {}).with_indifferent_access
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                    email_param  = params_options[:email]                 || 'user_email'
         
     | 
| 
      
 18 
     | 
    
         
            +
                    token_param  = params_options[:authentication_token]  || 'user_token'
         
     | 
| 
      
 19 
     | 
    
         
            +
                    email_header = headers_options[:email]                || 'X-User-Email'
         
     | 
| 
      
 20 
     | 
    
         
            +
                    token_header = headers_options[:authentication_token] || 'X-User-Token'
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                    email = params[email_param] || headers[email_header]
         
     | 
| 
      
 23 
     | 
    
         
            +
                    token = params[token_param] || headers[token_header]
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    return render_unauthorized if email.blank? || token.blank?
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                    case user_class.query "token #{Figaro.env.hub_app_name} #{email} #{token}"
         
     | 
| 
      
 28 
     | 
    
         
            +
                    when 'no'      then render_unauthorized
         
     | 
| 
      
 29 
     | 
    
         
            +
                    when 'invaild' then render_unauthorized
         
     | 
| 
      
 30 
     | 
    
         
            +
                    when 'sorry'   then render_internal_server_error
         
     | 
| 
      
 31 
     | 
    
         
            +
                    when 'yes'     then true
         
     | 
| 
      
 32 
     | 
    
         
            +
                    end
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  private
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                  def render_unauthorized
         
     | 
| 
      
 38 
     | 
    
         
            +
                    respond_to do |format|
         
     | 
| 
      
 39 
     | 
    
         
            +
                      format.json do
         
     | 
| 
      
 40 
     | 
    
         
            +
                        render status: :unauthorized,
         
     | 
| 
      
 41 
     | 
    
         
            +
                               json: { error: "Invalid or missing credentials" }
         
     | 
| 
      
 42 
     | 
    
         
            +
                      end
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  def render_internal_server_error
         
     | 
| 
      
 47 
     | 
    
         
            +
                    respond_to do |format|
         
     | 
| 
      
 48 
     | 
    
         
            +
                      format.json do
         
     | 
| 
      
 49 
     | 
    
         
            +
                        render status: :internal_server_error,
         
     | 
| 
      
 50 
     | 
    
         
            +
                               json: { error: "Authentication server broke" }
         
     | 
| 
      
 51 
     | 
    
         
            +
                      end
         
     | 
| 
      
 52 
     | 
    
         
            +
                    end
         
     | 
| 
      
 53 
     | 
    
         
            +
                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/softwear/lib.rb
    CHANGED
    
    
| 
         @@ -19,6 +19,17 @@ module Softwear 
     | 
|
| 
       19 
19 
     | 
    
         
             
                  self.class_attribute :resource_class, :instance_writer => false unless self.respond_to? :resource_class
         
     | 
| 
       20 
20 
     | 
    
         
             
                  self.class_attribute :parents_symbols,  :resources_configuration, :instance_writer => false
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
      
 22 
     | 
    
         
            +
                  def self.base_class
         
     | 
| 
      
 23 
     | 
    
         
            +
                    Softwear::Lib::ApiController
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  def self.token_authenticate(user_class, options = {})
         
     | 
| 
      
 27 
     | 
    
         
            +
                    include Softwear::Auth::TokenAuthentication
         
     | 
| 
      
 28 
     | 
    
         
            +
                    self.user_class = user_class
         
     | 
| 
      
 29 
     | 
    
         
            +
                    self.token_auth_options = options
         
     | 
| 
      
 30 
     | 
    
         
            +
                    prepend_before_filter :token_authenticate_user!
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
       22 
33 
     | 
    
         
             
                  def index(&block)
         
     | 
| 
       23 
34 
     | 
    
         
             
                    yield if block_given?
         
     | 
| 
       24 
35 
     | 
    
         | 
| 
         @@ -77,6 +88,10 @@ module Softwear 
     | 
|
| 
       77 
88 
     | 
    
         | 
| 
       78 
89 
     | 
    
         
             
                  protected
         
     | 
| 
       79 
90 
     | 
    
         | 
| 
      
 91 
     | 
    
         
            +
                  def base_class
         
     | 
| 
      
 92 
     | 
    
         
            +
                    self.class.base_class
         
     | 
| 
      
 93 
     | 
    
         
            +
                  end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
       80 
95 
     | 
    
         
             
                  def render_json(options = {})
         
     | 
| 
       81 
96 
     | 
    
         
             
                    proc do
         
     | 
| 
       82 
97 
     | 
    
         
             
                      if options.is_a?(Hash)
         
     | 
| 
         @@ -32,7 +32,7 @@ module Softwear 
     | 
|
| 
       32 
32 
     | 
    
         
             
                  # Action called when a NotSignedInError is raised.
         
     | 
| 
       33 
33 
     | 
    
         
             
                  # ====================
         
     | 
| 
       34 
34 
     | 
    
         
             
                  def user_not_signed_in
         
     | 
| 
       35 
     | 
    
         
            -
                    redirect_to  
     | 
| 
      
 35 
     | 
    
         
            +
                    redirect_to softwear_hub_url + "/users/sign_in?#{{return_to: request.original_url}.to_param}"
         
     | 
| 
       36 
36 
     | 
    
         
             
                  end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
                  # ====================
         
     | 
| 
         @@ -97,21 +97,21 @@ module Softwear 
     | 
|
| 
       97 
97 
     | 
    
         
             
                  end
         
     | 
| 
       98 
98 
     | 
    
         | 
| 
       99 
99 
     | 
    
         
             
                  def destroy_user_session_path
         
     | 
| 
       100 
     | 
    
         
            -
                     
     | 
| 
      
 100 
     | 
    
         
            +
                    softwear_hub_url + "/users/sign_out"
         
     | 
| 
       101 
101 
     | 
    
         
             
                  end
         
     | 
| 
       102 
102 
     | 
    
         | 
| 
       103 
103 
     | 
    
         
             
                  def user_path(user)
         
     | 
| 
       104 
104 
     | 
    
         
             
                    user_id = user.is_a?(user_class) ? user.id : user
         
     | 
| 
       105 
     | 
    
         
            -
                     
     | 
| 
      
 105 
     | 
    
         
            +
                    softwear_hub_url + "/users/#{user_id}"
         
     | 
| 
       106 
106 
     | 
    
         
             
                  end
         
     | 
| 
       107 
107 
     | 
    
         | 
| 
       108 
108 
     | 
    
         
             
                  def edit_user_path(user)
         
     | 
| 
       109 
109 
     | 
    
         
             
                    user_id = user.is_a?(user_class) ? user.id : user
         
     | 
| 
       110 
     | 
    
         
            -
                     
     | 
| 
      
 110 
     | 
    
         
            +
                    softwear_hub_url + "/users/#{user_id}/edit"
         
     | 
| 
       111 
111 
     | 
    
         
             
                  end
         
     | 
| 
       112 
112 
     | 
    
         | 
| 
       113 
113 
     | 
    
         
             
                  def users_path
         
     | 
| 
       114 
     | 
    
         
            -
                     
     | 
| 
      
 114 
     | 
    
         
            +
                    softwear_hub_url + "/users"
         
     | 
| 
       115 
115 
     | 
    
         
             
                  end
         
     | 
| 
       116 
116 
     | 
    
         | 
| 
       117 
117 
     | 
    
         
             
                  private
         
     | 
    
        data/lib/softwear/lib/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: softwear-lib
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.5. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.5.8
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Nigel Baillie
         
     | 
| 
         @@ -88,6 +88,7 @@ files: 
     | 
|
| 
       88 
88 
     | 
    
         
             
            - lib/softwear/auth/helper.rb
         
     | 
| 
       89 
89 
     | 
    
         
             
            - lib/softwear/auth/model.rb
         
     | 
| 
       90 
90 
     | 
    
         
             
            - lib/softwear/auth/spec.rb
         
     | 
| 
      
 91 
     | 
    
         
            +
            - lib/softwear/auth/token_authentication.rb
         
     | 
| 
       91 
92 
     | 
    
         
             
            - lib/softwear/lib.rb
         
     | 
| 
       92 
93 
     | 
    
         
             
            - lib/softwear/lib/api_controller.rb
         
     | 
| 
       93 
94 
     | 
    
         
             
            - lib/softwear/lib/authentication.rb
         
     |