verikloak-audience 0.2.4 → 0.2.6
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 +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +10 -2
- data/lib/generators/verikloak/audience/install/install_generator.rb +28 -0
- data/lib/verikloak/audience/railtie.rb +58 -3
- data/lib/verikloak/audience/version.rb +1 -1
- data/lib/verikloak/audience.rb +2 -1
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1ba5a1ca7162831839679e843f5def72fb8efeecb4b88e9cded4d6aa283c66a3
         | 
| 4 | 
            +
              data.tar.gz: 4a4a71f5408b0b77cb63ffa9b5bc998a721de2083133234b1dfa2e96c4afb609
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d54e6ccb8c86555cb3c3821355912fc283e155fb103cdb7df5a0166e59163f9ea086ea1a7fcdbb7c7a82aa76b65b120d166379cfacd18fcff610bdb9fe4fc65a
         | 
| 7 | 
            +
              data.tar.gz: c610ec408d85b8bd89b1a7f60d112731b3dbcaac696e66a993caa790c2ee5bb8c8b2f43227c87c681b3a1384fb59cca43e267ecd4a0f69f43f924187cc90f0ea
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |
| 7 7 |  | 
| 8 8 | 
             
            ---
         | 
| 9 9 |  | 
| 10 | 
            +
            ## [0.2.6] - 2025-09-23
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            ### Added
         | 
| 13 | 
            +
            - Rails generator `verikloak:audience:install` to create an initializer that inserts the audience middleware once the core Verikloak middleware is available.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            ### Changed
         | 
| 16 | 
            +
            - Improved warning message when core Verikloak middleware is not present in the Rails middleware stack.
         | 
| 17 | 
            +
            - Enhanced middleware insertion logic to provide clearer guidance on setup requirements.
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## [0.2.5] - 2025-09-23
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ### Changed
         | 
| 22 | 
            +
            - Use autoload for middleware to avoid circular require dependencies.
         | 
| 23 | 
            +
            - Improve module loading performance by deferring middleware class loading until accessed.
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            ### Added
         | 
| 26 | 
            +
            - Comprehensive test suite for standalone middleware require scenarios.
         | 
| 27 | 
            +
            - Test coverage for middleware functionality when loaded independently of main gem entrypoint.
         | 
| 28 | 
            +
             | 
| 10 29 | 
             
            ## [0.2.4] - 2025-09-22
         | 
| 11 30 |  | 
| 12 31 | 
             
            ### Fixed
         | 
    
        data/README.md
    CHANGED
    
    | @@ -30,9 +30,17 @@ For the full error behaviour (response shapes, exception classes, logging hints) | |
| 30 30 | 
             
            bundle add verikloak-audience
         | 
| 31 31 | 
             
            ```
         | 
| 32 32 |  | 
| 33 | 
            -
             | 
| 33 | 
            +
            In Rails applications, generate the initializer that automatically inserts the middleware:
         | 
| 34 34 |  | 
| 35 | 
            -
             | 
| 35 | 
            +
            ```bash
         | 
| 36 | 
            +
            rails g verikloak:audience:install
         | 
| 37 | 
            +
            ```
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            This creates `config/initializers/verikloak_audience.rb` that will insert the audience middleware after the core Verikloak middleware once it's available.
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            ## Manual Rack / Rails setup
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            Alternatively, you can manually insert **after** `Verikloak::Middleware`:
         | 
| 36 44 |  | 
| 37 45 | 
             
            ```ruby
         | 
| 38 46 | 
             
            # config/application.rb
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            begin
         | 
| 4 | 
            +
              require 'rails/generators'
         | 
| 5 | 
            +
              require 'rails/generators/base'
         | 
| 6 | 
            +
            rescue LoadError
         | 
| 7 | 
            +
              # Allow the generator to be required without Rails.
         | 
| 8 | 
            +
            end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            module Verikloak
         | 
| 11 | 
            +
              module Audience
         | 
| 12 | 
            +
                module Generators
         | 
| 13 | 
            +
                  # Installs the verikloak audience middleware configuration into a Rails
         | 
| 14 | 
            +
                  # application. This generator creates an initializer that inserts the
         | 
| 15 | 
            +
                  # audience middleware after the core Verikloak middleware once it is
         | 
| 16 | 
            +
                  # available.
         | 
| 17 | 
            +
                  class InstallGenerator < (defined?(Rails::Generators::Base) ? Rails::Generators::Base : Object)
         | 
| 18 | 
            +
                    source_root File.expand_path('templates', __dir__) if respond_to?(:source_root)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    def create_initializer
         | 
| 21 | 
            +
                      return unless respond_to?(:template, true)
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                      template 'verikloak_audience.rb.tt', 'config/initializers/verikloak_audience.rb'
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| @@ -42,15 +42,70 @@ module Verikloak | |
| 42 42 | 
             
                  end
         | 
| 43 43 |  | 
| 44 44 | 
             
                  # Performs the insertion into the middleware stack when the core
         | 
| 45 | 
            -
                  # Verikloak middleware is available. Extracted for | 
| 46 | 
            -
                  # requiring a full Rails boot process.
         | 
| 45 | 
            +
                  # Verikloak middleware is available and already present. Extracted for
         | 
| 46 | 
            +
                  # testability without requiring a full Rails boot process.
         | 
| 47 47 | 
             
                  #
         | 
| 48 48 | 
             
                  # @param app [#middleware] An object exposing a Rack middleware stack via `#middleware`.
         | 
| 49 49 | 
             
                  # @return [void]
         | 
| 50 50 | 
             
                  def self.insert_middleware(app)
         | 
| 51 51 | 
             
                    return unless defined?(::Verikloak::Middleware)
         | 
| 52 52 |  | 
| 53 | 
            -
                    app.middleware | 
| 53 | 
            +
                    middleware_stack = app.middleware
         | 
| 54 | 
            +
                    return unless middleware_stack.respond_to?(:include?)
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    unless middleware_stack.include?(::Verikloak::Middleware)
         | 
| 57 | 
            +
                      warn_missing_core_middleware
         | 
| 58 | 
            +
                      return
         | 
| 59 | 
            +
                    end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                    middleware_stack.insert_after ::Verikloak::Middleware, ::Verikloak::Audience::Middleware
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  WARNING_MESSAGE = <<~MSG
         | 
| 65 | 
            +
                    [verikloak-audience] Skipping automatic middleware insertion because ::Verikloak::Middleware
         | 
| 66 | 
            +
                    is not present in the Rails middleware stack.
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                    To enable verikloak-audience, first ensure that the core Verikloak middleware (`Verikloak::Middleware`)
         | 
| 69 | 
            +
                    is added to your Rails middleware stack. Once the core middleware is present, you can run
         | 
| 70 | 
            +
                    `rails g verikloak:audience:install` to generate the initializer for the audience middleware,
         | 
| 71 | 
            +
                    or manually add:
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                      config.middleware.insert_after Verikloak::Middleware, Verikloak::Audience::Middleware
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                    This warning will disappear once the core middleware is properly configured and the audience
         | 
| 76 | 
            +
                    middleware is inserted.
         | 
| 77 | 
            +
                  MSG
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                  # Logs a warning message when the core Verikloak middleware is missing
         | 
| 80 | 
            +
                  # from the Rails middleware stack. Uses the Rails logger if available,
         | 
| 81 | 
            +
                  # otherwise falls back to Kernel.warn for output.
         | 
| 82 | 
            +
                  #
         | 
| 83 | 
            +
                  # This method is called when automatic middleware insertion is skipped
         | 
| 84 | 
            +
                  # due to the absence of the required core middleware.
         | 
| 85 | 
            +
                  #
         | 
| 86 | 
            +
                  # @return [void]
         | 
| 87 | 
            +
                  def self.warn_missing_core_middleware
         | 
| 88 | 
            +
                    logger = rails_logger
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                    if logger
         | 
| 91 | 
            +
                      logger.warn(WARNING_MESSAGE)
         | 
| 92 | 
            +
                    else
         | 
| 93 | 
            +
                      Kernel.warn(WARNING_MESSAGE)
         | 
| 94 | 
            +
                    end
         | 
| 95 | 
            +
                  end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                  # Retrieves the Rails application logger if available.
         | 
| 98 | 
            +
                  #
         | 
| 99 | 
            +
                  # This method safely attempts to access the Rails logger, returning nil
         | 
| 100 | 
            +
                  # if Rails is not defined, doesn't respond to the logger method, or if
         | 
| 101 | 
            +
                  # the logger itself is nil.
         | 
| 102 | 
            +
                  #
         | 
| 103 | 
            +
                  # @return [Logger, nil] the Rails logger instance, or nil if unavailable
         | 
| 104 | 
            +
                  def self.rails_logger
         | 
| 105 | 
            +
                    return unless defined?(::Rails)
         | 
| 106 | 
            +
                    return unless ::Rails.respond_to?(:logger)
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                    ::Rails.logger
         | 
| 54 109 | 
             
                  end
         | 
| 55 110 |  | 
| 56 111 | 
             
                  # Rails short commands (`g`, `d`) are stripped from ARGV fairly early in
         | 
    
        data/lib/verikloak/audience.rb
    CHANGED
    
    | @@ -5,13 +5,14 @@ require 'verikloak/audience/version' | |
| 5 5 | 
             
            require 'verikloak/audience/configuration'
         | 
| 6 6 | 
             
            require 'verikloak/audience/errors'
         | 
| 7 7 | 
             
            require 'verikloak/audience/checker'
         | 
| 8 | 
            -
            require 'verikloak/audience/middleware'
         | 
| 9 8 | 
             
            require 'verikloak/audience/railtie' if defined?(Rails::Railtie)
         | 
| 10 9 |  | 
| 11 10 | 
             
            module Verikloak
         | 
| 12 11 | 
             
              # Audience configuration entrypoint and helpers.
         | 
| 13 12 | 
             
              # This file also requires the public components of the gem.
         | 
| 14 13 | 
             
              module Audience
         | 
| 14 | 
            +
                autoload :Middleware, 'verikloak/audience/middleware'
         | 
| 15 | 
            +
             | 
| 15 16 | 
             
                class << self
         | 
| 16 17 | 
             
                  # Configure verikloak-audience.
         | 
| 17 18 | 
             
                  #
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: verikloak-audience
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.6
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - taiyaky
         | 
| @@ -59,6 +59,7 @@ files: | |
| 59 59 | 
             
            - CHANGELOG.md
         | 
| 60 60 | 
             
            - LICENSE
         | 
| 61 61 | 
             
            - README.md
         | 
| 62 | 
            +
            - lib/generators/verikloak/audience/install/install_generator.rb
         | 
| 62 63 | 
             
            - lib/verikloak-audience.rb
         | 
| 63 64 | 
             
            - lib/verikloak/audience.rb
         | 
| 64 65 | 
             
            - lib/verikloak/audience/checker.rb
         | 
| @@ -74,7 +75,7 @@ metadata: | |
| 74 75 | 
             
              source_code_uri: https://github.com/taiyaky/verikloak-audience
         | 
| 75 76 | 
             
              changelog_uri: https://github.com/taiyaky/verikloak-audience/blob/main/CHANGELOG.md
         | 
| 76 77 | 
             
              bug_tracker_uri: https://github.com/taiyaky/verikloak-audience/issues
         | 
| 77 | 
            -
              documentation_uri: https://rubydoc.info/gems/verikloak-audience/0.2. | 
| 78 | 
            +
              documentation_uri: https://rubydoc.info/gems/verikloak-audience/0.2.6
         | 
| 78 79 | 
             
              rubygems_mfa_required: 'true'
         | 
| 79 80 | 
             
            rdoc_options: []
         | 
| 80 81 | 
             
            require_paths:
         |