heimdall_auth 1.8.0 → 1.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62917a5dfbec560e91964ae280d362973e51c3fd7aec9fa39012fcba2053fb96
4
- data.tar.gz: d902146d018ba779759c7bef16e7807266d1960a49127961d587a791f131ee41
3
+ metadata.gz: 224f15277c180a85265f085959acfbf033543335add8a4989717c4eb486b3a0a
4
+ data.tar.gz: b7fb140f8184ace1ed89f04054f7d3c2abfdb503aef9aa3b68d2bf4911f89406
5
5
  SHA512:
6
- metadata.gz: b47b0dfd4f6db45ab8a1d5a34626e1529dcba2811901c36e3ba9a1534e5a814b7c163a4ed433198c66462575feb2eadbd60792ac604f53703381c88cf0282cbc
7
- data.tar.gz: 97c6c1a896670c6e224725d848e30340cf30baeecca65a24d7f12275d8040ad1ebdd1bc75156295eda8b94c847901a34802e0542145a2a02a75fdc09a38de91a
6
+ metadata.gz: 16c9d7755c9bfaaa4ab9d80b8737554ec9319eb768fa4ae48e87ca1dd7641d500706e60a39e666116efb3e1508601454b663f0f3d90b86418a5f8ebbd082ef05
7
+ data.tar.gz: 9d1b07f0e74d1bdc07594f68d2e2ef9041e73c0ffd4039e2cf428dab480a6516a44fdb5fd8f065b6a428291d7ece97fa7e2c9761c136ec90416b56c9c79551a4
data/README.md CHANGED
@@ -5,6 +5,11 @@ This makes it easy to equip an empty rails application with our Heimdall Auth fe
5
5
  Use it like so in `config/routes.rb`:
6
6
  ```
7
7
  mount_heimdall_auth_secured Sidekiq::Web => '/sidekiq', :manage => :sidekiq
8
+
9
+ or
10
+
11
+ # The /sidekiq/stats path gets available for services like Datadog
12
+ mount_heimdall_auth_secured Sidekiq::Web => '/sidekiq', :manage => :sidekiq, accessible_via_token: {'/sidekiq/stats': ENV['SIDEKIQ_STATS_TOKEN_FOR_WATCHDOG']}
8
13
  ```
9
14
  instead of the known:
10
15
  ```
@@ -18,11 +23,18 @@ if user.is_admin
18
23
  end
19
24
  ```
20
25
 
26
+ and the password in `.env` and `.env.example` if you used it:
27
+ ```
28
+ SIDEKIQ_STATS_TOKEN_FOR_WATCHDOG=halloweltrandomstring
29
+ ```
30
+
21
31
  Options:
22
- - mount_heimdall_auth_secured ENGINE => PATH, ACTION => RESOURCE
23
- - ENGINE - any mountable Engine like `Sidekiq::Web`
24
- - PATH - where to mount the engine
25
- - ACTION & RESOURCE - like any action and resource in cancancan
32
+ - mount_heimdall_auth_secured ENGINE => PATH, ACTION => RESOURCE, accessible_via_token: {EXCEPTION_PATH: EXCEPTION_PASSWORD, EXCEPTION_PATH2: EXCEPTION_PASSWORD2}
33
+ - ENGINE - any mountable Engine like `Sidekiq::Web`
34
+ - PATH - where to mount the engine
35
+ - ACTION & RESOURCE - like any action and resource in cancancan
36
+ - :accessible_via_token -> Defines paths that are available via a particular token. e.g. for Watchdog services like Datadog
37
+ - URL needs then to have the token as `?token=secretpassword` in the query params. Like: `https://webhook.vesputi-abc.de/sidekiq/stats?token=secretpassword`
26
38
 
27
39
  ## Installation and Usage
28
40
 
@@ -103,3 +115,26 @@ RSpec.describe "/foobar", type: :request do
103
115
  before { allow_any_instance_of(ApplicationController).to receive(:current_user) { HeimdallAuth::User.new(is_editor: true) } }
104
116
  end
105
117
  ```
118
+
119
+ # Usage with RSpec
120
+ ## Simulate an Admin user
121
+
122
+ See the example:
123
+ ```ruby
124
+ require 'rails_helper'
125
+
126
+ RSpec.describe "/cards", type: :request do
127
+
128
+ let(:admin_user) {
129
+ HeimdallAuth::User.new(email: "foo@bar.com", is_admin: true)
130
+ }
131
+
132
+ describe "GET /index" do
133
+ before(:each) do
134
+ allow_any_instance_of( HeimdallAuth::ControllerAdditions ).to receive(:current_user).and_return(admin_user)
135
+ end
136
+
137
+ it "renders a successful response" do
138
+ Card.create! valid_attributes
139
+ get cards_url
140
+ ```
@@ -14,7 +14,7 @@ class HeimdallAuth::SessionsController < ApplicationController
14
14
 
15
15
  def create
16
16
  auth = request.env["omniauth.auth"]
17
- session[:access_token] = auth.credentials.token
17
+ session[:access_token] = auth&.credentials&.token
18
18
  redirect_to( session[:last_url] || request.base_url, allow_other_host: true)
19
19
  end
20
20
 
@@ -29,7 +29,7 @@ module HeimdallAuth
29
29
 
30
30
  def current_environment
31
31
  begin
32
- @current_environment ||= current_user.key_environment || params[:environment]
32
+ @current_environment ||= current_user.app_environment || params[:environment]
33
33
  rescue NoMethodError, Exception => e
34
34
  nil
35
35
  end
@@ -12,16 +12,19 @@ module HeimdallAuth
12
12
 
13
13
 
14
14
  def mount_heimdall_auth_secured(options = {}, &block)
15
- mount_element = options.keys.first
16
- path = options[mount_element]
15
+ accessible_via_token = options.extract!(:accessible_via_token)[:accessible_via_token]
16
+
17
+ engine = options.keys.first #Syntax sugar ENGINE => PATH, ACTION => RESOURCE
18
+ path = options.values.first #Syntax sugar ENGINE => PATH, ACTION => RESOURCE
19
+
20
+ action = options.keys.second #Syntax sugar ENGINE => PATH, ACTION => RESOURCE
21
+ resource = options.values.second #Syntax sugar ENGINE => PATH, ACTION => RESOURCE
17
22
 
18
- action = options.keys.second
19
- resource = options.values.second
20
23
  if action.nil? || resource.nil?
21
24
  puts "WARNING: It seems you missed the cancancan rights. Use: `mount_heimdall_auth_secured Sidekiq::Web => '/sidekiq', :manage => :sidekiq`"
22
25
  end
23
26
 
24
- mount mount_element => path, constraints: HeimdallAuth::RouteConstraint.new(action, resource)
27
+ mount engine => path, constraints: HeimdallAuth::RouteConstraint.new(action, resource, accessible_via_token)
25
28
  get "#{path}", to: redirect('/signin')
26
29
  get "#{path}/*rest", to: redirect('/signin')
27
30
  end
@@ -32,12 +32,24 @@ module HeimdallAuth
32
32
 
33
33
  class RouteConstraint
34
34
 
35
- def initialize(action, resource)
35
+ def initialize(action, resource, accessible_via_token)
36
36
  @action = action
37
37
  @resource = resource
38
+ @accessible_via_token = accessible_via_token
38
39
  end
39
40
 
40
41
  def matches?(matching_request)
42
+ if @accessible_via_token && matching_request.query_parameters["token"]
43
+ @accessible_via_token.keys.each do |path|
44
+ if path.to_s == matching_request.path.to_s
45
+ expected_token = @accessible_via_token[path]
46
+ if expected_token && ActiveSupport::SecurityUtils.secure_compare(matching_request.query_parameters["token"], expected_token)
47
+ return true
48
+ end
49
+ end
50
+ end
51
+ end
52
+
41
53
  AuthenticationChecker.new(matching_request).can?(@action, @resource)
42
54
  end
43
55
 
@@ -1,3 +1,3 @@
1
1
  module HeimdallAuth
2
- VERSION = '1.8.0'
2
+ VERSION = '1.10.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heimdall_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - René Meye
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-28 00:00:00.000000000 Z
11
+ date: 2026-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
- rubygems_version: 3.3.7
142
+ rubygems_version: 3.3.27
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Summary of HeimdallAuth.