Class: ForestLiana::Authentication

Inherits:
Object
  • Object
show all
Defined in:
app/services/forest_liana/authentication.rb

Instance Method Summary collapse

Instance Method Details

#start_authentication(state) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'app/services/forest_liana/authentication.rb', line 3

def start_authentication(state)
  client = ForestLiana::OidcClientManager.get_client()

  authorization_url = client.authorization_uri({
    scope: 'openid email profile',
    state: state.to_s,
  })

  { 'authorization_url' => authorization_url }
end

#verify_code_and_generate_token(params) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/forest_liana/authentication.rb', line 14

def verify_code_and_generate_token(params)
  client = ForestLiana::OidcClientManager.get_client()

  rendering_id = parse_state(params['state'])
  client.authorization_code = params['code']

  if Rails.env.development? || Rails.env.test?
    OpenIDConnect.http_config do |config|
      config.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end
  end
  access_token_instance = client.access_token! 'none'

  user = ForestLiana::AuthorizationGetter.authenticate(
    rendering_id,
    { :forest_token => access_token_instance.instance_variable_get(:@access_token) },
  )

  return ForestLiana::Token.create_token(user, rendering_id)
end