-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
15 changed files
with
208 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,17 @@ | ||
class ApplicationController < ActionController::Base | ||
before_action :identify_user | ||
|
||
private | ||
|
||
def identify_user | ||
Current.user = PivotIdentity.new(auth: session_auth, recipient:) | ||
end | ||
|
||
def recipient | ||
params.fetch(:recipient, "") | ||
end | ||
|
||
def session_auth | ||
session.fetch("auth", {}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class ClaimsController < ApplicationController | ||
def index | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class HomeController < ApplicationController | ||
def home | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class SessionsController < ApplicationController | ||
def new | ||
render :new | ||
end | ||
|
||
def create | ||
session[:auth] = request.env["omniauth.auth"] | ||
|
||
redirect_to claims_path(recipient: "13002526500013") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Current < ActiveSupport::CurrentAttributes | ||
attribute :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class PivotIdentity | ||
extend HashMapper | ||
|
||
attr_reader :auth, :data | ||
|
||
map from("info/birthdate"), to("birthdate") { |str| Date.strptime(str, "%Y-%m-%d") } | ||
map from("info/family_name"), to("family_name") | ||
map from("info/first_name"), to("first_names") { |str| str.split(" ") } | ||
map from("info/gender"), to("gender") | ||
map from("info/last_name"), to("last_name") | ||
map from("extra/raw_info/birthcountry"), to("birth_country") | ||
map from("extra/raw_info/birthplace"), to("birthplace") | ||
|
||
map from("credentials/token"), to("token") | ||
|
||
def initialize(recipient:, auth: {}) | ||
@auth = auth | ||
@data = self.class.normalize(auth) | ||
@data[:recipient] = recipient | ||
end | ||
|
||
delegate :[], to: :data | ||
|
||
def token | ||
return "cnaf_qfv2" unless Rails.env.production? | ||
|
||
self[:token] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h1 class="w-full">Début de la demande</h1> | ||
<div class="flex-auto"> | ||
|
||
<pre> | ||
curl -H "Authorization: Bearer <%= Current.user.token %>" -G \ | ||
-d 'recipient=<%= Current.user[:recipient] %>' \ | ||
--url "https://staging.particulier.api.gouv.fr/api/v2/composition-familiale-v2"</pre> | ||
</div> | ||
<hr class="flex-auto" /> | ||
<div class="flex-auto"><%= debug Current.user %></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Faire une demande</h1> | ||
<%= link_to "Je démarre", :claims %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= form_tag('/auth/france_connect', method: 'post', data: {turbo: false}) do %> | ||
<button type='submit'>Login with FC</button> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require "omniauth_openid_connect" | ||
|
||
module OmniAuth | ||
module Strategies | ||
class FranceConnect < OpenIDConnect | ||
option :callback_path, "/callback" | ||
option :client_auth_method, :secret | ||
option :client_signing_alg, :HS256 | ||
option :state, -> { SecureRandom.hex(16) } | ||
|
||
option :client_options, { | ||
port: 443, | ||
scheme: "https", | ||
authorization_endpoint: "/api/v1/authorize?acr_values=eidas1", | ||
token_endpoint: "/api/v1/token", | ||
userinfo_endpoint: "/api/v1/userinfo", | ||
} | ||
end | ||
end | ||
end | ||
|
||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
provider( | ||
:france_connect, | ||
client_options: { | ||
host: Settings.france_connect.host, | ||
identifier: Settings.france_connect.identifier, | ||
redirect_uri: Settings.france_connect.redirect_uri, | ||
secret: Settings.france_connect.secret, | ||
}, | ||
issuer: "https://#{Settings.france_connect.host}", | ||
name: :france_connect, | ||
scope: %i[openid identite_pivot] | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
# keys from rails' credentials are added under "credentials" (cf config_add_credentials.rb) | ||
france_connect: | ||
host: "fcp.integ01.dev-franceconnect.fr" | ||
identifier: "211286433e39cce01db448d80181bdfd005554b19cd51b3fe7943f6b3b86ab6e" | ||
redirect_uri: "http://localhost:3000/callback" | ||
secret: "2791a731e6a59f56b6b4dd0d08c9b1f593b5f3658b9fd731cb24248e2669af4b" | ||
hubee: | ||
base_url: "https://api.bas.hubee.numerique.gouv.fr" | ||
client_id: <%= Rails.application.credentials.hubee.client_id %> | ||
client_secret: <%= Rails.application.credentials.hubee.client_secret %> | ||
token_url: "https://auth.bas.hubee.numerique.gouv.fr/oauth2/token" |