diff --git a/.gitignore b/.gitignore index d6c9550c6..303c6304d 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ bin/* config/initializers/token.rb doc/*.svg rubocop.html +config/france_connect.yml \ No newline at end of file diff --git a/Gemfile b/Gemfile index 47c9b9fac..2be2cc7d8 100644 --- a/Gemfile +++ b/Gemfile @@ -42,6 +42,7 @@ gem 'draper' #Gestion des comptes utilisateurs gem 'devise' +gem 'openid_connect' gem 'rest-client' gem 'carrierwave' @@ -61,6 +62,8 @@ gem 'logstasher' gem "font-awesome-rails" +gem 'hashie' + group :test do gem 'capybara' gem 'factory_girl' diff --git a/Gemfile.lock b/Gemfile.lock index c456bc24f..25e3f8612 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,10 +49,12 @@ GEM ast (2.0.0) astrolabe (1.3.0) parser (>= 2.2.0.pre.3, < 3.0) + attr_required (1.0.0) autoprefixer-rails (5.2.1) execjs json bcrypt (3.1.10) + bindata (2.1.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) bootstrap-datepicker-rails (1.4.0) @@ -126,6 +128,7 @@ GEM haml (>= 4.0.6, < 5.0) html2haml (>= 1.0.1) railties (>= 4.0.1) + hashie (3.4.1) html2haml (2.0.0) erubis (~> 2.7.0) haml (~> 4.0.0) @@ -133,6 +136,7 @@ GEM ruby_parser (~> 3.5) http-cookie (1.0.2) domain_name (~> 0.5) + httpclient (2.6.0.1) i18n (0.7.0) jbuilder (2.3.1) activesupport (>= 3.0.0, < 5) @@ -142,6 +146,12 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.3) + json-jwt (1.5.1) + activesupport + bindata + multi_json (>= 1.3) + securecompare + url_safe_base64 kgio (2.9.3) leaflet-draw-rails (0.1.0) leaflet-markercluster-rails (0.7.0) @@ -165,6 +175,17 @@ GEM nokogiri (1.6.6.2) mini_portile (~> 0.6.0) 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) parser (2.2.2.2) ast (>= 1.1, < 3.0) @@ -183,6 +204,12 @@ GEM byebug (~> 5.0) pry (~> 0.10) 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 (>= 1.0) railroady (1.3.0) @@ -266,6 +293,7 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + securecompare (1.0.0) selenium-webdriver (2.44.0) childprocess (~> 0.5) multi_json (~> 1.0) @@ -291,6 +319,12 @@ GEM actionpack (>= 3.0) activesupport (>= 3.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) thread_safe (0.3.5) tilt (1.4.1) @@ -309,6 +343,13 @@ GEM kgio (~> 2.6) rack 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) rack (>= 1.0) web-console (2.2.1) @@ -316,6 +357,10 @@ GEM binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) + webfinger (1.0.1) + activesupport + httpclient (>= 2.4) + multi_json webmock (1.21.0) addressable (>= 2.3.6) crack (>= 0.3.2) @@ -343,6 +388,7 @@ DEPENDENCIES factory_girl font-awesome-rails haml-rails + hashie jbuilder (~> 2.0) jquery-rails leaflet-draw-rails @@ -350,6 +396,7 @@ DEPENDENCIES leaflet-rails logstasher mina! + openid_connect pg poltergeist pry-byebug diff --git a/app/controllers/fc_controller.rb b/app/controllers/fc_controller.rb new file mode 100644 index 000000000..4d786a11e --- /dev/null +++ b/app/controllers/fc_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/test_open_id_controller.rb b/app/controllers/test_open_id_controller.rb new file mode 100644 index 000000000..b43a55e46 --- /dev/null +++ b/app/controllers/test_open_id_controller.rb @@ -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 \ No newline at end of file diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 647a8e193..085c383a0 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -49,11 +49,11 @@ class Dossier < ActiveRecord::Base end 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' end - unless ['user', 'gestionnaire'].include?(role) + unless %w(user gestionnaire).include?(role) fail 'role is not valid' end diff --git a/app/views/test_open_id/show.html.haml b/app/views/test_open_id/show.html.haml new file mode 100644 index 000000000..b210f42db --- /dev/null +++ b/app/views/test_open_id/show.html.haml @@ -0,0 +1 @@ +%h1 coucou \ No newline at end of file diff --git a/config/initializers/france_connect.rb b/config/initializers/france_connect.rb new file mode 100644 index 000000000..77046a5c1 --- /dev/null +++ b/config/initializers/france_connect.rb @@ -0,0 +1,2 @@ +file_path = "#{Rails.root}/config/france_connect.yml" +FRANCE_CONNECT = Hashie::Mash.load(file_path) \ No newline at end of file diff --git a/config/initializers/open_id_connect.rb b/config/initializers/open_id_connect.rb new file mode 100644 index 000000000..ff380c704 --- /dev/null +++ b/config/initializers/open_id_connect.rb @@ -0,0 +1,5 @@ +OpenIDConnect.debug! +OpenIDConnect.logger = Rails.logger +Rack::OAuth2.logger = Rails.logger +# Webfinger.logger = Rails.logger +SWD.logger = Rails.logger \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index bcb55575a..d9a081e7a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,8 +9,11 @@ Rails.application.routes.draw do }, 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 get 'siret' => 'siret#index'