Allow pass a Proc to the setup option when you specify a strategy (#18)

Co-authored-by: Jose Luis Cambero <joseluis.cambero@sngular.com>
master
Cambero 2021-12-18 22:39:56 +01:00 committed by GitHub
parent cc236ae6fe
commit 09b68aab71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View File

@ -30,6 +30,26 @@ Rails.application.config.middleware.use OmniAuth::Builder do
end
```
Or using a proc setup with a custom options:
```ruby
Rails.application.config.middleware.use OmniAuth::Builder do
SETUP_PROC = lambda do |env|
request = Rack::Request.new(env)
organization = Organization.find_by(host: request.host)
provider_config = organization.enabled_omniauth_providers[:keycloakopenid]
env["omniauth.strategy"].options[:client_id] = provider_config[:client_id]
env["omniauth.strategy"].options[:client_secret] = provider_config[:client_secret]
env["omniauth.strategy"].options[:client_options] = { site: provider_config[:site], realm: provider_config[:realm] }
end
Rails.application.config.middleware.use OmniAuth::Builder do
provider :keycloak_openid, setup: SETUP_PROC
end
end
```
This will allow a POST request to `auth/keycloak`
## Devise Usage

View File

@ -16,6 +16,8 @@ module OmniAuth
attr_reader :certs
def setup_phase
super
if @authorize_url.nil? || @token_url.nil?
prevent_site_option_mistake

View File

@ -47,6 +47,16 @@ RSpec.describe OmniAuth::Strategies::KeycloakOpenId do
end
end
context 'client setup with a proc' do
subject do
OmniAuth::Strategies::KeycloakOpenId.new('keycloak-openid', setup: proc { throw :setup_proc_was_called })
end
it 'should call the proc' do
expect { subject.setup_phase }.to throw_symbol :setup_proc_was_called
end
end
describe 'errors processing' do
context 'when site contains /auth part' do
subject do