Skip to content

Commit eff0984

Browse files
authored
Set redirect uri (#53)
When multiple redirect URIs are set in Hydra, it needs a redirect_uri param specifying. I had assumed that the `callback_path` would be enough, but it turns out I was wrong. This expeclicitly sets the redirect_uri parameter when initiating the login flow.
1 parent 89be12c commit eff0984

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Ensure `redirect_uri` is set in the OpenID Connect configuration (#53)
13+
1014
## [v3.0.0]
1115

1216
### Changed

config/routes.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
# Dummy routes. These routes are never reached in the app, as Omniauth
55
# intercepts it via Rack middleware before it reaches Rails, however adding
66
# them allows us to use rpi_auth_login_path helpers etc.
7-
post '/auth/rpi', as: :rpi_auth_login, params: { login_options: 'v1_signup' }
8-
post '/auth/rpi', as: :rpi_auth_signup, params: { login_options: 'force_signup,v1_signup' }
7+
post RpiAuth::Engine::LOGIN_PATH, as: :rpi_auth_login, params: { login_options: 'v1_signup' }
8+
post RpiAuth::Engine::LOGIN_PATH, as: :rpi_auth_signup, params: { login_options: 'force_signup,v1_signup' }
99

10-
namespace 'rpi_auth' do
11-
get '/auth/callback', to: 'auth#callback', as: 'callback'
12-
get '/logout', to: 'auth#destroy', as: 'logout'
13-
end
10+
get RpiAuth::Engine::CALLBACK_PATH, to: 'rpi_auth/auth#callback', as: 'rpi_auth_callback'
11+
get RpiAuth::Engine::LOGOUT_PATH, to: 'rpi_auth/auth#destroy', as: 'rpi_auth_logout'
1412
end

lib/rpi_auth/engine.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class Engine < ::Rails::Engine
99

1010
using ::RpiAuthBypass
1111

12+
LOGIN_PATH = '/auth/rpi'
13+
CALLBACK_PATH = '/rpi_auth/auth/callback'
14+
LOGOUT_PATH = '/rpi_auth/logout'
15+
1216
initializer 'RpiAuth.set_logger' do
1317
OmniAuth.config.logger = Rails.logger
1418
end
@@ -22,7 +26,7 @@ class Engine < ::Rails::Engine
2226
name: :rpi,
2327
issuer: RpiAuth.configuration.issuer,
2428
scope: RpiAuth.configuration.scope,
25-
callback_path: '/rpi_auth/auth/callback',
29+
callback_path: CALLBACK_PATH,
2630
response_type: RpiAuth.configuration.response_type,
2731
client_auth_method: RpiAuth.configuration.client_auth_method,
2832
client_options: {
@@ -33,7 +37,8 @@ class Engine < ::Rails::Engine
3337
port: RpiAuth.configuration.token_endpoint.port,
3438
authorization_endpoint: RpiAuth.configuration.authorization_endpoint,
3539
token_endpoint: RpiAuth.configuration.token_endpoint,
36-
jwks_uri: RpiAuth.configuration.jwks_uri
40+
jwks_uri: RpiAuth.configuration.jwks_uri,
41+
redirect_uri: URI.join(RpiAuth.configuration.host_url, CALLBACK_PATH)
3742
},
3843
extra_authorize_params: { brand: RpiAuth.configuration.brand },
3944
allow_authorize_params: [:login_options],

spec/dummy/config/initializers/rpi_auth.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@
1010

1111
config.bypass_auth = false
1212

13-
# Profile is running in docker, so we need to set this manually. This
14-
# shouldn't be needed elsewhere, unless you're getting errors saying:
15-
# Invalid ID token: Issuer does not match
16-
config.issuer = "http://host.docker.internal:9001/"
13+
# In development, the issuer is set in the docker-compose.yml file in the
14+
# Profile repo. If you see errors like
15+
#
16+
# (rpi) Authentication failure! Invalid ID token: Issuer does not match
17+
#
18+
# then set the issuer here to match the value in the docker-compose file.
19+
# When Hydra is running, the issue value can also be viewed at
20+
# http://localhost:9001/.well-known/openid-configuration
21+
#
22+
# In staging/production this shouldn't be an issue, as all the hostnames are
23+
# the same.
24+
config.issuer = "http://localhost:9001/"
1725
end

0 commit comments

Comments
 (0)