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
parent
cc236ae6fe
commit
09b68aab71
20
README.md
20
README.md
|
@ -30,6 +30,26 @@ Rails.application.config.middleware.use OmniAuth::Builder do
|
||||||
end
|
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`
|
This will allow a POST request to `auth/keycloak`
|
||||||
|
|
||||||
## Devise Usage
|
## Devise Usage
|
||||||
|
|
|
@ -16,6 +16,8 @@ module OmniAuth
|
||||||
attr_reader :certs
|
attr_reader :certs
|
||||||
|
|
||||||
def setup_phase
|
def setup_phase
|
||||||
|
super
|
||||||
|
|
||||||
if @authorize_url.nil? || @token_url.nil?
|
if @authorize_url.nil? || @token_url.nil?
|
||||||
prevent_site_option_mistake
|
prevent_site_option_mistake
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,16 @@ RSpec.describe OmniAuth::Strategies::KeycloakOpenId do
|
||||||
end
|
end
|
||||||
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
|
describe 'errors processing' do
|
||||||
context 'when site contains /auth part' do
|
context 'when site contains /auth part' do
|
||||||
subject do
|
subject do
|
||||||
|
|
Loading…
Reference in New Issue