Skip to content

Commit e2b057e

Browse files
committed
Ajoute FranceConnect ainsi qu'un squelette de navigation
Ce commit ajoute une connexion basique à FranceConnect et génère des commandes curls pour tester la récupération des données auprès d'api-particulier.
1 parent e56f294 commit e2b057e

File tree

15 files changed

+208
-28
lines changed

15 files changed

+208
-28
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ gem "bootsnap", require: false
4545
# gem "image_processing", "~> 1.2"
4646

4747
gem "config"
48+
gem "omniauth_openid_connect"
49+
gem "hash_mapper"
50+
gem "omniauth-rails_csrf_protection"
4851

4952
group :development, :test do
5053
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem

Gemfile.lock

Lines changed: 72 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ GEM
7777
tzinfo (~> 2.0)
7878
addressable (2.8.6)
7979
public_suffix (>= 2.0.2, < 6.0)
80+
aes_key_wrap (1.1.0)
8081
ast (2.4.2)
82+
attr_required (1.0.2)
8183
base64 (0.2.0)
8284
bigdecimal (3.1.7)
85+
bindata (2.5.0)
8386
bindex (0.8.1)
8487
bootsnap (1.18.3)
8588
msgpack (~> 1.2)
@@ -104,9 +107,20 @@ GEM
104107
reline (>= 0.3.8)
105108
deep_merge (1.2.2)
106109
drb (2.2.1)
110+
email_validator (2.2.4)
111+
activemodel
107112
erubi (1.12.0)
113+
faraday (2.9.0)
114+
faraday-net_http (>= 2.0, < 3.2)
115+
faraday-follow_redirects (0.3.0)
116+
faraday (>= 1, < 3)
117+
faraday-net_http (3.1.0)
118+
net-http
108119
globalid (1.2.1)
109120
activesupport (>= 6.1)
121+
hash_mapper (0.2.7)
122+
activesupport (>= 4)
123+
hashie (5.0.0)
110124
i18n (1.14.4)
111125
concurrent-ruby (~> 1.0)
112126
importmap-rails (2.0.1)
@@ -121,6 +135,13 @@ GEM
121135
actionview (>= 5.0.0)
122136
activesupport (>= 5.0.0)
123137
json (2.7.2)
138+
json-jwt (1.16.6)
139+
activesupport (>= 4.2)
140+
aes_key_wrap
141+
base64
142+
bindata
143+
faraday (~> 2.0)
144+
faraday-follow_redirects
124145
language_server-protocol (3.17.0.3)
125146
lint_roller (1.1.0)
126147
loofah (2.22.0)
@@ -137,6 +158,8 @@ GEM
137158
minitest (5.22.3)
138159
msgpack (1.7.2)
139160
mutex_m (0.2.0)
161+
net-http (0.4.1)
162+
uri
140163
net-imap (0.4.10)
141164
date
142165
net-protocol
@@ -147,18 +170,31 @@ GEM
147170
net-smtp (0.5.0)
148171
net-protocol
149172
nio4r (2.7.1)
150-
nokogiri (1.16.3-aarch64-linux)
151-
racc (~> 1.4)
152-
nokogiri (1.16.3-arm-linux)
153-
racc (~> 1.4)
154-
nokogiri (1.16.3-arm64-darwin)
155-
racc (~> 1.4)
156-
nokogiri (1.16.3-x86-linux)
157-
racc (~> 1.4)
158-
nokogiri (1.16.3-x86_64-darwin)
159-
racc (~> 1.4)
160173
nokogiri (1.16.3-x86_64-linux)
161174
racc (~> 1.4)
175+
omniauth (2.1.2)
176+
hashie (>= 3.4.6)
177+
rack (>= 2.2.3)
178+
rack-protection
179+
omniauth-rails_csrf_protection (1.0.1)
180+
actionpack (>= 4.2)
181+
omniauth (~> 2.0)
182+
omniauth_openid_connect (0.7.1)
183+
omniauth (>= 1.9, < 3)
184+
openid_connect (~> 2.2)
185+
openid_connect (2.3.0)
186+
activemodel
187+
attr_required (>= 1.0.0)
188+
email_validator
189+
faraday (~> 2.0)
190+
faraday-follow_redirects
191+
json-jwt (>= 1.16)
192+
mail
193+
rack-oauth2 (~> 2.2)
194+
swd (~> 2.0)
195+
tzinfo
196+
validate_url
197+
webfinger (~> 2.0)
162198
parallel (1.24.0)
163199
parser (3.3.0.5)
164200
ast (~> 2.4.1)
@@ -171,6 +207,16 @@ GEM
171207
nio4r (~> 2.0)
172208
racc (1.7.3)
173209
rack (3.0.10)
210+
rack-oauth2 (2.2.1)
211+
activesupport
212+
attr_required
213+
faraday (~> 2.0)
214+
faraday-follow_redirects
215+
json-jwt (>= 1.11.0)
216+
rack (>= 2.1.0)
217+
rack-protection (4.0.0)
218+
base64 (>= 0.1.0)
219+
rack (>= 3.0.0, < 4)
174220
rack-session (2.0.0)
175221
rack (>= 3.0.0)
176222
rack-test (2.1.0)
@@ -265,16 +311,11 @@ GEM
265311
stimulus-rails (1.3.3)
266312
railties (>= 6.0.0)
267313
stringio (3.1.0)
268-
tailwindcss-rails (2.3.0)
269-
railties (>= 6.0.0)
270-
tailwindcss-rails (2.3.0-aarch64-linux)
271-
railties (>= 6.0.0)
272-
tailwindcss-rails (2.3.0-arm-linux)
273-
railties (>= 6.0.0)
274-
tailwindcss-rails (2.3.0-arm64-darwin)
275-
railties (>= 6.0.0)
276-
tailwindcss-rails (2.3.0-x86_64-darwin)
277-
railties (>= 6.0.0)
314+
swd (2.0.3)
315+
activesupport (>= 3)
316+
attr_required (>= 0.0.5)
317+
faraday (~> 2.0)
318+
faraday-follow_redirects
278319
tailwindcss-rails (2.3.0-x86_64-linux)
279320
railties (>= 6.0.0)
280321
thor (1.3.1)
@@ -286,11 +327,19 @@ GEM
286327
tzinfo (2.0.6)
287328
concurrent-ruby (~> 1.0)
288329
unicode-display_width (2.5.0)
330+
uri (0.13.0)
331+
validate_url (1.0.15)
332+
activemodel (>= 3.0.0)
333+
public_suffix
289334
web-console (4.2.1)
290335
actionview (>= 6.0.0)
291336
activemodel (>= 6.0.0)
292337
bindex (>= 0.4.0)
293338
railties (>= 6.0.0)
339+
webfinger (2.1.3)
340+
activesupport
341+
faraday (~> 2.0)
342+
faraday-follow_redirects
294343
webrick (1.8.1)
295344
websocket (1.2.10)
296345
websocket-driver (0.7.6)
@@ -301,20 +350,18 @@ GEM
301350
zeitwerk (2.6.13)
302351

303352
PLATFORMS
304-
aarch64-linux
305-
arm-linux
306-
arm64-darwin
307-
x86-linux
308-
x86_64-darwin
309353
x86_64-linux
310354

311355
DEPENDENCIES
312356
bootsnap
313357
capybara
314358
config
315359
debug
360+
hash_mapper
316361
importmap-rails
317362
jbuilder
363+
omniauth-rails_csrf_protection
364+
omniauth_openid_connect
318365
pg (~> 1.1)
319366
puma (>= 5.0)
320367
rails (~> 7.1.3, >= 7.1.3.2)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
class ApplicationController < ActionController::Base
2+
before_action :identify_user
3+
4+
private
5+
6+
def identify_user
7+
Current.user = PivotIdentity.new(auth: session_auth, recipient:)
8+
end
9+
10+
def recipient
11+
params.fetch(:recipient, "")
12+
end
13+
14+
def session_auth
15+
session.fetch("auth", {})
16+
end
217
end

app/controllers/claims_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class ClaimsController < ApplicationController
2+
def index
3+
end
4+
end

app/controllers/home_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class HomeController < ApplicationController
2+
def home
3+
end
4+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class SessionsController < ApplicationController
2+
def new
3+
render :new
4+
end
5+
6+
def create
7+
session[:auth] = request.env["omniauth.auth"]
8+
9+
redirect_to claims_path(recipient: "13002526500013")
10+
end
11+
end

app/models/current.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Current < ActiveSupport::CurrentAttributes
2+
attribute :user
3+
end

app/models/pivot_identity.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class PivotIdentity
2+
extend HashMapper
3+
4+
attr_reader :auth, :data
5+
6+
map from("info/birthdate"), to("birthdate") { |str| Date.strptime(str, "%Y-%m-%d") }
7+
map from("info/family_name"), to("family_name")
8+
map from("info/first_name"), to("first_names") { |str| str.split(" ") }
9+
map from("info/gender"), to("gender")
10+
map from("info/last_name"), to("last_name")
11+
map from("extra/raw_info/birthcountry"), to("birth_country")
12+
map from("extra/raw_info/birthplace"), to("birthplace")
13+
14+
map from("credentials/token"), to("token")
15+
16+
def initialize(recipient:, auth: {})
17+
@auth = auth
18+
@data = self.class.normalize(auth)
19+
@data[:recipient] = recipient
20+
end
21+
22+
delegate :[], to: :data
23+
24+
def token
25+
return "cnaf_qfv2" unless Rails.env.production?
26+
27+
self[:token]
28+
end
29+
end

app/views/claims/index.html.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<h1 class="w-full">Début de la demande</h1>
2+
<div class="flex-auto">
3+
4+
<pre>
5+
curl -H "Authorization: Bearer <%= Current.user.token %>" -G \
6+
-d 'recipient=<%= Current.user[:recipient] %>' \
7+
--url "https://staging.particulier.api.gouv.fr/api/v2/composition-familiale-v2"</pre>
8+
</div>
9+
<hr class="flex-auto" />
10+
<div class="flex-auto"><%= debug Current.user %></div>

app/views/home/index.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<h1>Faire une demande</h1>
2+
<%= link_to "Je démarre", :claims %>

0 commit comments

Comments
 (0)