Class: NulogySSO::AuthenticationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Auth0::Api::AuthenticationEndpoints, Auth0::Mixins::HTTPProxy
Defined in:
app/controllers/nulogy_sso/authentication_controller.rb

Overview

This controller adds routes to power SSO authentication when this engine is mounted into a Rails app.

Instance Method Summary collapse

Constructor Details

#initializeAuthenticationController

Returns a new instance of AuthenticationController.



12
13
14
15
16
# File 'app/controllers/nulogy_sso/authentication_controller.rb', line 12

def initialize
  # These instance variables have to be set in order for the HTTPProxy mixin to work.
  @base_uri = sso_config.base_uri
  @headers = { content_type: "application/json" }
end

Instance Method Details

#loginObject



18
19
20
21
22
23
24
25
26
# File 'app/controllers/nulogy_sso/authentication_controller.rb', line 18

def 
  raw_access_token = token_store.fetch

  authenticator.validate_token(
    raw_access_token,
    on_success: method(:on_authentication_success),
    on_invalid_token: ->(_e) { redirect_to auth0_authorize_path, allow_other_host: true }
  )
end

#logoutObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/nulogy_sso/authentication_controller.rb', line 43

def logout
  token_store.forget!

  query_params = {
    returnTo: sso_config.redirect_uri, # Yes, this must be camelCased
    client_id: sso_config.client_id
  }
  redirect_to "#{sso_config.base_uri}/v2/logout?#{query_params.to_query}", allow_other_host: true
end

#verify_authentication_codeObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/nulogy_sso/authentication_controller.rb', line 28

def verify_authentication_code
  code = params.require(:code)
  begin
    raw_access_token = fetch_token_from_auth0(code)
  rescue Auth0::Exception => e
    return sso_error(e)
  end

  authenticator.validate_token(
    raw_access_token,
    on_success: method(:on_authentication_success),
    on_invalid_token: ->(e) { sso_error(e) }
  )
end