Intégration France Connect - sans les tests
This commit is contained in:
parent
40d5802d4a
commit
fd60692ade
19 changed files with 86 additions and 337 deletions
|
@ -1,22 +0,0 @@
|
|||
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
|
27
app/controllers/france_connect_controller.rb
Normal file
27
app/controllers/france_connect_controller.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
class FranceConnectController < ApplicationController
|
||||
def index
|
||||
client = FranceConnectClient.new
|
||||
|
||||
session[:state] = SecureRandom.hex(16)
|
||||
session[:nonce] = SecureRandom.hex(16)
|
||||
|
||||
authorization_uri = client.authorization_uri(
|
||||
scope: [:profile, :email],
|
||||
state: session[:state],
|
||||
nonce: session[:nonce]
|
||||
)
|
||||
redirect_to authorization_uri
|
||||
end
|
||||
|
||||
def callback
|
||||
user_infos = FranceConnectService.retrive_user(params[:code])
|
||||
|
||||
unless user_infos.nil?
|
||||
@user = User.find_for_france_connect(user_infos.email)
|
||||
|
||||
sign_in @user
|
||||
|
||||
redirect_to(controller: 'users/dossiers', action: :index)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,31 +0,0 @@
|
|||
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
|
|
@ -1,28 +0,0 @@
|
|||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
# You should configure your model like this:
|
||||
# devise :omniauthable, omniauth_providers: [:twitter]
|
||||
|
||||
# You should also create an action method in this controller like this:
|
||||
# def twitter
|
||||
# end
|
||||
|
||||
# More info at:
|
||||
# https://github.com/plataformatec/devise#omniauth
|
||||
|
||||
# GET|POST /resource/auth/twitter
|
||||
# def passthru
|
||||
# super
|
||||
# end
|
||||
|
||||
# GET|POST /users/auth/twitter/callback
|
||||
# def failure
|
||||
# super
|
||||
# end
|
||||
|
||||
# protected
|
||||
|
||||
# The path used when omniauth fails
|
||||
# def after_omniauth_failure_path_for(scope)
|
||||
# super(scope)
|
||||
# end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue