start france connect

This commit is contained in:
Tanguy PATTE 2015-10-05 16:42:29 +02:00
parent 7f91778027
commit 40d5802d4a
10 changed files with 119 additions and 4 deletions

1
.gitignore vendored
View file

@ -28,3 +28,4 @@ bin/*
config/initializers/token.rb config/initializers/token.rb
doc/*.svg doc/*.svg
rubocop.html rubocop.html
config/france_connect.yml

View file

@ -42,6 +42,7 @@ gem 'draper'
#Gestion des comptes utilisateurs #Gestion des comptes utilisateurs
gem 'devise' gem 'devise'
gem 'openid_connect'
gem 'rest-client' gem 'rest-client'
gem 'carrierwave' gem 'carrierwave'
@ -61,6 +62,8 @@ gem 'logstasher'
gem "font-awesome-rails" gem "font-awesome-rails"
gem 'hashie'
group :test do group :test do
gem 'capybara' gem 'capybara'
gem 'factory_girl' gem 'factory_girl'

View file

@ -49,10 +49,12 @@ GEM
ast (2.0.0) ast (2.0.0)
astrolabe (1.3.0) astrolabe (1.3.0)
parser (>= 2.2.0.pre.3, < 3.0) parser (>= 2.2.0.pre.3, < 3.0)
attr_required (1.0.0)
autoprefixer-rails (5.2.1) autoprefixer-rails (5.2.1)
execjs execjs
json json
bcrypt (3.1.10) bcrypt (3.1.10)
bindata (2.1.0)
binding_of_caller (0.7.2) binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
bootstrap-datepicker-rails (1.4.0) bootstrap-datepicker-rails (1.4.0)
@ -126,6 +128,7 @@ GEM
haml (>= 4.0.6, < 5.0) haml (>= 4.0.6, < 5.0)
html2haml (>= 1.0.1) html2haml (>= 1.0.1)
railties (>= 4.0.1) railties (>= 4.0.1)
hashie (3.4.1)
html2haml (2.0.0) html2haml (2.0.0)
erubis (~> 2.7.0) erubis (~> 2.7.0)
haml (~> 4.0.0) haml (~> 4.0.0)
@ -133,6 +136,7 @@ GEM
ruby_parser (~> 3.5) ruby_parser (~> 3.5)
http-cookie (1.0.2) http-cookie (1.0.2)
domain_name (~> 0.5) domain_name (~> 0.5)
httpclient (2.6.0.1)
i18n (0.7.0) i18n (0.7.0)
jbuilder (2.3.1) jbuilder (2.3.1)
activesupport (>= 3.0.0, < 5) activesupport (>= 3.0.0, < 5)
@ -142,6 +146,12 @@ GEM
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (1.8.3) json (1.8.3)
json-jwt (1.5.1)
activesupport
bindata
multi_json (>= 1.3)
securecompare
url_safe_base64
kgio (2.9.3) kgio (2.9.3)
leaflet-draw-rails (0.1.0) leaflet-draw-rails (0.1.0)
leaflet-markercluster-rails (0.7.0) leaflet-markercluster-rails (0.7.0)
@ -165,6 +175,17 @@ GEM
nokogiri (1.6.6.2) nokogiri (1.6.6.2)
mini_portile (~> 0.6.0) mini_portile (~> 0.6.0)
open4 (1.3.4) open4 (1.3.4)
openid_connect (0.9.2)
activemodel
attr_required (>= 1.0.0)
json (>= 1.4.3)
json-jwt (>= 1.5.0)
rack-oauth2 (>= 1.2.1)
swd (>= 1.0.0)
tzinfo
validate_email
validate_url
webfinger (>= 1.0.1)
orm_adapter (0.5.0) orm_adapter (0.5.0)
parser (2.2.2.2) parser (2.2.2.2)
ast (>= 1.1, < 3.0) ast (>= 1.1, < 3.0)
@ -183,6 +204,12 @@ GEM
byebug (~> 5.0) byebug (~> 5.0)
pry (~> 0.10) pry (~> 0.10)
rack (1.6.4) rack (1.6.4)
rack-oauth2 (1.2.1)
activesupport (>= 2.3)
attr_required (>= 0.0.5)
httpclient (>= 2.4)
multi_json (>= 1.3.6)
rack (>= 1.1)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
railroady (1.3.0) railroady (1.3.0)
@ -266,6 +293,7 @@ GEM
sdoc (0.4.1) sdoc (0.4.1)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0) rdoc (~> 4.0)
securecompare (1.0.0)
selenium-webdriver (2.44.0) selenium-webdriver (2.44.0)
childprocess (~> 0.5) childprocess (~> 0.5)
multi_json (~> 1.0) multi_json (~> 1.0)
@ -291,6 +319,12 @@ GEM
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
swd (1.0.0)
activesupport (>= 3)
attr_required (>= 0.0.5)
httpclient (>= 2.4)
i18n
json (>= 1.4.3)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (1.4.1) tilt (1.4.1)
@ -309,6 +343,13 @@ GEM
kgio (~> 2.6) kgio (~> 2.6)
rack rack
raindrops (~> 0.7) raindrops (~> 0.7)
url_safe_base64 (0.2.2)
validate_email (0.1.6)
activemodel (>= 3.0)
mail (>= 2.2.5)
validate_url (1.0.2)
activemodel (>= 3.0.0)
addressable
warden (1.2.3) warden (1.2.3)
rack (>= 1.0) rack (>= 1.0)
web-console (2.2.1) web-console (2.2.1)
@ -316,6 +357,10 @@ GEM
binding_of_caller (>= 0.7.2) binding_of_caller (>= 0.7.2)
railties (>= 4.0) railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0) sprockets-rails (>= 2.0, < 4.0)
webfinger (1.0.1)
activesupport
httpclient (>= 2.4)
multi_json
webmock (1.21.0) webmock (1.21.0)
addressable (>= 2.3.6) addressable (>= 2.3.6)
crack (>= 0.3.2) crack (>= 0.3.2)
@ -343,6 +388,7 @@ DEPENDENCIES
factory_girl factory_girl
font-awesome-rails font-awesome-rails
haml-rails haml-rails
hashie
jbuilder (~> 2.0) jbuilder (~> 2.0)
jquery-rails jquery-rails
leaflet-draw-rails leaflet-draw-rails
@ -350,6 +396,7 @@ DEPENDENCIES
leaflet-rails leaflet-rails
logstasher logstasher
mina! mina!
openid_connect
pg pg
poltergeist poltergeist
pry-byebug pry-byebug

View file

@ -0,0 +1,22 @@
class FcController < ApplicationController
def index
client = OpenIDConnect::Client.new(
identifier: FRANCE_CONNECT.identifier,
secret: FRANCE_CONNECT.secret,
redirect_uri: 'http://localhost:3000',
authorization_endpoint: 'https://fce.integ01.dev-franceconnect.fr/api/v1/authorize',
token_endpoint: 'https://fce.integ01.dev-franceconnect.fr/api/v1/token',
userinfo_endpoint: 'https://fce.integ01.dev-franceconnect.fr/api/v1/userinfo'
)
session[:state] = SecureRandom.hex(16)
session[:nonce] = SecureRandom.hex(16)
authorization_uri = client.authorization_uri(
state: session[:state],
nonce: session[:nonce]
)
redirect_to authorization_uri
end
end

View file

@ -0,0 +1,31 @@
class TestOpenIdController < ApplicationController
def show
client = OpenIDConnect::Client.new(
identifier: FRANCE_CONNECT.identifier,
secret: FRANCE_CONNECT.secret,
redirect_uri: 'http://localhost:3000',
authorization_endpoint: 'https://fce.integ01.dev-franceconnect.fr/api/v1/authorize',
token_endpoint: 'https://fce.integ01.dev-franceconnect.fr/api/v1/token',
userinfo_endpoint: 'https://fce.integ01.dev-franceconnect.fr/api/v1/userinfo'
)
client.authorization_code = params[:code]
begin
access_token = client.access_token!(client_auth_method: :secret)
id_token = OpenIDConnect::ResponseObject::IdToken.decode access_token.id_token, FRANCE_CONNECT.secret
puts id_token
userinfo = access_token.userinfo!
puts userinfo
rescue Exception => e
puts e.message
end
end
end

View file

@ -49,11 +49,11 @@ class Dossier < ActiveRecord::Base
end end
def next_step! role, action def next_step! role, action
unless ['propose', 'reply', 'update', 'comment', 'confirme', 'depose', 'process'].include?(action) unless %w(propose reply update comment confirme depose process).include?(action)
fail 'action is not valid' fail 'action is not valid'
end end
unless ['user', 'gestionnaire'].include?(role) unless %w(user gestionnaire).include?(role)
fail 'role is not valid' fail 'role is not valid'
end end

View file

@ -0,0 +1 @@
%h1 coucou

View file

@ -0,0 +1,2 @@
file_path = "#{Rails.root}/config/france_connect.yml"
FRANCE_CONNECT = Hashie::Mash.load(file_path)

View file

@ -0,0 +1,5 @@
OpenIDConnect.debug!
OpenIDConnect.logger = Rails.logger
Rack::OAuth2.logger = Rails.logger
# Webfinger.logger = Rails.logger
SWD.logger = Rails.logger

View file

@ -9,8 +9,11 @@ Rails.application.routes.draw do
}, skip: [:password, :registrations] }, skip: [:password, :registrations]
# root 'welcome#index'
root 'users/dossiers#index' # root 'users/dossiers#index'
root 'test_open_id#show'
get '/fc' => 'fc#index'
namespace :users do namespace :users do
get 'siret' => 'siret#index' get 'siret' => 'siret#index'