Skip to content

Commit 79f3392

Browse files
committed
Get dummy app running locally
1 parent 48db0e4 commit 79f3392

File tree

10 files changed

+46
-21
lines changed

10 files changed

+46
-21
lines changed

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ GEM
163163
byebug (~> 11.0)
164164
pry (>= 0.13, < 0.15)
165165
public_suffix (5.0.1)
166+
puma (6.2.2)
167+
nio4r (~> 2.0)
166168
racc (1.6.2)
167169
rack (2.2.7)
168170
rack-oauth2 (2.2.0)
@@ -289,6 +291,7 @@ PLATFORMS
289291
DEPENDENCIES
290292
listen
291293
pry-byebug
294+
puma
292295
rails (~> 7.0)
293296
rpi_auth!
294297
rspec-rails

lib/rpi_auth/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module RpiAuth
44
class Configuration
55
using ::RpiAuthBypass
66

7-
attr_writer :auth_token_url
7+
attr_writer :auth_token_url, :issuer
88

99
attr_accessor :auth_client_id,
1010
:auth_client_secret,

lib/rpi_auth_bypass.rb

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,42 @@ module RpiAuthBypass
1212
DEFAULT_COUNTRY = 'United Kingdom'
1313
DEFAULT_COUNTRY_CODE = 'GB'
1414
DEFAULT_POSTCODE = 'SW1A 1AA'
15+
1516
DEFAULT_INFO = {
1617
name: DEFAULT_NAME,
1718
nickname: DEFAULT_NICKNAME,
1819
email: DEFAULT_EMAIL,
20+
email_verified: true,
1921
username: DEFAULT_USERNAME,
2022
image: DEFAULT_IMAGE
2123
}.freeze
24+
2225
DEFAULT_EXTRA = {
2326
raw_info: {
24-
roles: DEFAULT_ROLES,
25-
name: DEFAULT_NAME,
26-
nickname: DEFAULT_NICKNAME,
27-
email: DEFAULT_EMAIL,
28-
username: DEFAULT_USERNAME,
2927
country: DEFAULT_COUNTRY,
3028
country_code: DEFAULT_COUNTRY_CODE,
29+
email: DEFAULT_EMAIL,
30+
email_verified: true,
31+
name: DEFAULT_NAME,
32+
nickname: DEFAULT_NICKNAME,
33+
picture: DEFAULT_IMAGE,
3134
postcode: DEFAULT_POSTCODE,
3235
profile: DEFAULT_PROFILE,
33-
avatar: DEFAULT_IMAGE
36+
roles: DEFAULT_ROLES,
37+
sub: DEFAULT_UID,
38+
user: DEFAULT_UID,
39+
username: DEFAULT_USERNAME
3440
}
3541
}.freeze
3642

43+
DEFAULT_CREDENTIALS = {
44+
id_token: 'dummy-id-token',
45+
token: 'dummy-access-token',
46+
refresh_token: 'dummy-refresh-token',
47+
expires_in: 3600,
48+
scope: 'openid email profile force-consent roles offline'
49+
}.freeze
50+
3751
refine OmniAuth::Configuration do
3852
def enable_rpi_auth_bypass
3953
logger.info 'Enabling RpiAuthBypass'
@@ -49,13 +63,16 @@ def disable_rpi_auth_bypass
4963
self.test_mode = self.rpi_auth_bypass = false
5064
end
5165

52-
def add_rpi_mock(uid: RpiAuthBypass::DEFAULT_UID, info: RpiAuthBypass::DEFAULT_INFO,
53-
extra: RpiAuthBypass::DEFAULT_EXTRA)
66+
def add_rpi_mock(uid: RpiAuthBypass::DEFAULT_UID,
67+
info: RpiAuthBypass::DEFAULT_INFO,
68+
extra: RpiAuthBypass::DEFAULT_EXTRA,
69+
credentials: RpiAuthBypass::DEFAULT_CREDENTIALS)
5470
add_mock(:rpi, {
55-
provider: 'Rpi',
71+
provider: :rpi,
5672
uid: uid,
5773
info: info,
58-
extra: extra
74+
extra: extra,
75+
credentials: credentials
5976
})
6077
end
6178

rpi_auth.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
2727

2828
spec.add_development_dependency 'listen'
2929
spec.add_development_dependency 'pry-byebug'
30+
spec.add_development_dependency 'puma'
3031
spec.add_development_dependency 'rspec_junit_formatter'
3132
spec.add_development_dependency 'rspec-rails'
3233
spec.add_development_dependency 'rubocop'
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
class HomeController < ApplicationController
22
def show
3-
current_user
43
end
54
end

spec/dummy/app/views/home/show.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
Logged in as <%= current_user.user_id %>
66
<%= link_to 'Log out', rpi_auth_logout_path, class: 'button' %>
77
<% else %>
8-
<%= link_to 'Log in', rpi_auth_login_path, method: :post %>
9-
8+
<%= button_to 'Log in', rpi_auth_login_path, method: :post %>
9+
<br />
1010
<%= link_to 'Log in GET', rpi_auth_login_path %>
1111
<% end %>
1212
</p>

spec/dummy/app/views/layouts/application.html.erb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
<meta name="viewport" content="width=device-width,initial-scale=1">
66
<%= csrf_meta_tags %>
77
<%= csp_meta_tag %>
8-
9-
<%= stylesheet_link_tag "application" %>
108
</head>
119

1210
<body>

spec/dummy/config/environments/development.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@
4343
config.active_support.disallowed_deprecation_warnings = []
4444

4545
# Raise an error on page load if there are pending migrations.
46-
config.active_record.migration_error = :page_load
46+
# config.active_record.migration_error = :page_load
4747

4848
# Highlight code that triggered database queries in logs.
49-
config.active_record.verbose_query_logs = true
49+
# config.active_record.verbose_query_logs = true
5050

5151
# Suppress logger output for asset requests.
52-
config.assets.quiet = true
52+
# config.assets.quiet = true
5353

5454
# Raises error for missing translations.
5555
# config.i18n.raise_on_missing_translations = true

spec/dummy/config/initializers/rpi_auth.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
config.auth_url = 'http://localhost:9001'
33
config.auth_client_id = 'gem-dev'
44
config.auth_client_secret = 'secret'
5+
config.scope = %w[email force-consent openid profile roles allow-u13-login require-parental-consent]
56
config.brand = 'codeclub'
6-
config.host_url = 'http://localhost:3000'
7+
config.host_url = 'http://localhost:3009'
78
config.identity_url = 'http://localhost:3002'
89
config.user_model = 'User'
10+
11+
# Profile is running in docker, so we need to set this manually. This
12+
# shouldn't be needed elsewhere, unless you're getting errors saying:
13+
# Invalid ID token: Issuer does not match
14+
config.issuer = "http://host.docker.internal:9001/"
915
end

spec/dummy/config/routes.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
33
root to: 'home#show'
44

5-
get '/*slug', to: 'home#show'
5+
# Make sure we don't match auth routes
6+
get '/*slug', to: 'home#show', constraints: { slug: /(?!(rpi_)?auth\/).*/ }
67
end

0 commit comments

Comments
 (0)