Sha256: d5805ee97a2427da57bd5a965959f9ba6c3601d7ef17eed6c8f0a36f9cb6d5a0

Contents?: true

Size: 1.67 KB

Versions: 66

Compression:

Stored size: 1.67 KB

Contents

module ForestLiana
  class Authentication
    def start_authentication(redirect_url, state)
      client = ForestLiana::OidcClientManager.get_client_for_callback_url(redirect_url)

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

    def verify_code_and_generate_token(redirect_url, params) 
      client = ForestLiana::OidcClientManager.get_client_for_callback_url(redirect_url)

      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

    private
    def parse_state(state)
      unless state
        raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_STATE_MISSING]
      end

      rendering_id = nil

      begin
        parsed_state = JSON.parse(state.gsub("'",'"').gsub('=>',':'))
        rendering_id = parsed_state["renderingId"].to_s
      rescue
        raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_STATE_FORMAT]
      end

      if rendering_id.nil?
        raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_STATE_RENDERING_ID]
      end

      return rendering_id
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
forest_liana-7.6.14 app/services/forest_liana/authentication.rb
forest_liana-7.6.13 app/services/forest_liana/authentication.rb
forest_liana-7.6.12 app/services/forest_liana/authentication.rb
forest_liana-7.6.11 app/services/forest_liana/authentication.rb
forest_liana-7.6.10 app/services/forest_liana/authentication.rb
forest_liana-7.6.9 app/services/forest_liana/authentication.rb
forest_liana-7.6.8 app/services/forest_liana/authentication.rb
forest_liana-7.6.7 app/services/forest_liana/authentication.rb
forest_liana-7.6.6 app/services/forest_liana/authentication.rb
forest_liana-7.6.5 app/services/forest_liana/authentication.rb
forest_liana-7.6.4 app/services/forest_liana/authentication.rb
forest_liana-7.6.3 app/services/forest_liana/authentication.rb
forest_liana-7.6.2 app/services/forest_liana/authentication.rb
forest_liana-7.6.1 app/services/forest_liana/authentication.rb
forest_liana-7.6.0 app/services/forest_liana/authentication.rb
forest_liana-7.5.1 app/services/forest_liana/authentication.rb
forest_liana-7.5.0 app/services/forest_liana/authentication.rb
forest_liana-7.4.5 app/services/forest_liana/authentication.rb
forest_liana-7.4.4 app/services/forest_liana/authentication.rb
forest_liana-7.4.3 app/services/forest_liana/authentication.rb