jwt_api_auth 0.0.1.pre.3 → 0.0.1
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 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7441f7b62410f35d8fc01fcafd27930b0dbc2fd3db708ca0e21ebea89e2c27b8
         | 
| 4 | 
            +
              data.tar.gz: 7f936398e7b8d7e448817664c4e5ac4534bd6aa50029d5cd897bcc66281ffc20
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f67477f665a448748c2e043495208ce5d27c1ac9079504cf4818640fc2c00f99832c83537cb5a7eeba52d6dc0318d9b84f1f61bd244dc88cb4c7bf1e0fb41eb4
         | 
| 7 | 
            +
              data.tar.gz: ad95ac8d77cc31a108647ad1a057f1c15f77112e25d57e91cbfc53b3f9504ebf484023ab9e4cac4f86a97c599698e62b56f50f37abb70c7178ca7943ad9763f5
         | 
| @@ -2,24 +2,12 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            module JwtApiAuth
         | 
| 4 4 | 
             
              class ApplicationController < ActionController::Base
         | 
| 5 | 
            -
                 | 
| 6 | 
            -
                before_action :authenticate_user
         | 
| 5 | 
            +
                include JwtApiAuth::Authentication
         | 
| 7 6 |  | 
| 8 | 
            -
                 | 
| 9 | 
            -
                  head :unauthorized
         | 
| 10 | 
            -
                end
         | 
| 7 | 
            +
                skip_before_action :verify_authenticity_token
         | 
| 11 8 |  | 
| 12 9 | 
             
                rescue_from ActiveRecord::RecordNotFound do
         | 
| 13 10 | 
             
                  head :not_found
         | 
| 14 11 | 
             
                end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                private
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                def authenticate_user
         | 
| 19 | 
            -
                  token = request.headers['Authorization']&.split('Bearer ')&.last
         | 
| 20 | 
            -
                  ::JWT.decode token, JwtApiAuth.token_secret.call, true, { algorithm: 'HS256' }
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                  head :unauthorized unless token
         | 
| 23 | 
            -
                end
         | 
| 24 12 | 
             
              end
         | 
| 25 13 | 
             
            end
         | 
    
        data/lib/jwt_api_auth.rb
    CHANGED
    
    | @@ -3,6 +3,7 @@ | |
| 3 3 | 
             
            require 'jwt'
         | 
| 4 4 | 
             
            require 'jwt_api_auth/engine'
         | 
| 5 5 | 
             
            require 'jwt_api_auth/helpers'
         | 
| 6 | 
            +
            require 'jwt_api_auth/authentication'
         | 
| 6 7 |  | 
| 7 8 | 
             
            module JwtApiAuth
         | 
| 8 9 | 
             
              ActiveSupport.on_load(:action_controller) do
         | 
| @@ -23,4 +24,11 @@ module JwtApiAuth | |
| 23 24 |  | 
| 24 25 | 
             
              mattr_accessor :refresh_token_model
         | 
| 25 26 | 
             
              self.refresh_token_model = :refresh_token
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              mattr_accessor :token_audience
         | 
| 29 | 
            +
              self.token_audience = nil
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              def self.setup
         | 
| 32 | 
            +
                yield self
         | 
| 33 | 
            +
              end
         | 
| 26 34 | 
             
            end
         | 
| @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module JwtApiAuth
         | 
| 4 | 
            +
              module Authentication
         | 
| 5 | 
            +
                extend ActiveSupport::Concern
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                included do
         | 
| 8 | 
            +
                  before_action :authenticate_user
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  rescue_from ::JWT::DecodeError do
         | 
| 11 | 
            +
                    head :unauthorized
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                private
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def authenticate_user
         | 
| 18 | 
            +
                  token = request.headers['Authorization']&.split('Bearer ')&.last
         | 
| 19 | 
            +
                  options = { algorithm: 'HS256' }
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  if JwtApiAuth.token_audience.present?
         | 
| 22 | 
            +
                    options[:aud] = JwtApiAuth.token_audience.map(&:to_s)
         | 
| 23 | 
            +
                    options[:verify_aud] = true
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  ::JWT.decode token, JwtApiAuth.token_secret.call, true, options
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  head :unauthorized unless token
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
    
        data/lib/jwt_api_auth/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: jwt_api_auth
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0.1 | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Cristian Stügelmayer
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020-12- | 
| 11 | 
            +
            date: 2020-12-22 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: jwt
         | 
| @@ -269,6 +269,7 @@ files: | |
| 269 269 | 
             
            - app/views/layouts/jwt_api_auth/application.html.erb
         | 
| 270 270 | 
             
            - config/routes.rb
         | 
| 271 271 | 
             
            - lib/jwt_api_auth.rb
         | 
| 272 | 
            +
            - lib/jwt_api_auth/authentication.rb
         | 
| 272 273 | 
             
            - lib/jwt_api_auth/engine.rb
         | 
| 273 274 | 
             
            - lib/jwt_api_auth/helpers.rb
         | 
| 274 275 | 
             
            - lib/jwt_api_auth/version.rb
         | 
| @@ -289,9 +290,9 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 289 290 | 
             
                  version: '0'
         | 
| 290 291 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 291 292 | 
             
              requirements:
         | 
| 292 | 
            -
              - - " | 
| 293 | 
            +
              - - ">="
         | 
| 293 294 | 
             
                - !ruby/object:Gem::Version
         | 
| 294 | 
            -
                  version:  | 
| 295 | 
            +
                  version: '0'
         | 
| 295 296 | 
             
            requirements: []
         | 
| 296 297 | 
             
            rubygems_version: 3.0.8
         | 
| 297 298 | 
             
            signing_key: 
         |