demarches-normaliennes/app/services/agent_connect_service.rb

29 lines
570 B
Ruby
Raw Normal View History

2021-11-19 10:00:04 +01:00
class AgentConnectService
def self.enabled?
ENV.fetch("AGENT_CONNECT_ENABLED", "enabled") == "enabled"
end
2021-11-19 10:21:47 +01:00
def self.authorization_uri
client = AgentConnectClient.new
2022-04-11 13:11:04 +02:00
state = SecureRandom.hex(16)
uri = client.authorization_uri(
2021-11-19 10:21:47 +01:00
scope: [:openid, :email],
2022-04-11 13:11:04 +02:00
state: state,
2021-11-19 10:21:47 +01:00
nonce: SecureRandom.hex(16),
acr_values: 'eidas1'
)
2022-04-11 13:11:04 +02:00
[uri, state]
2021-11-19 10:21:47 +01:00
end
2021-11-19 15:24:54 +01:00
def self.user_info(code)
client = AgentConnectClient.new(code)
client.access_token!(client_auth_method: :secret)
.userinfo!
.raw_attributes
end
2021-11-19 10:00:04 +01:00
end