Module: Wor::Authentication::Controller

Defined in:
lib/wor/authentication/controller.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_entity(_params) ⇒ Object



64
65
66
# File 'lib/wor/authentication/controller.rb', line 64

def authenticate_entity(_params)
  {}
end

#authenticate_requestObject



6
7
8
9
# File 'lib/wor/authentication/controller.rb', line 6

def authenticate_request
  entity = find_authenticable_entity(decoded_token)
  decoded_token.validate!(entity_custom_validation_value(entity))
end

#authentication_tokenObject



37
38
39
40
41
42
# File 'lib/wor/authentication/controller.rb', line 37

def authentication_token
  if request.headers['Authorization'].blank?
    raise Wor::Authentication::Exceptions::MissingAuthorizationHeader
  end
  request.headers['Authorization'].split(' ').last
end

#current_entityObject



25
26
27
# File 'lib/wor/authentication/controller.rb', line 25

def current_entity
  @current_entity ||= find_authenticable_entity(decoded_token)
end

#decoded_tokenObject



11
12
13
14
15
# File 'lib/wor/authentication/controller.rb', line 11

def decoded_token
  @decoded_token ||= Wor::Authentication::TokenManager.new(
    token_key
  ).decode(authentication_token)
end

#entity_custom_validation_invalidate_all_value(_entity) ⇒ Object



52
53
54
# File 'lib/wor/authentication/controller.rb', line 52

def entity_custom_validation_invalidate_all_value(_entity)
  nil
end

#entity_custom_validation_renew_value(entity) ⇒ Object



48
49
50
# File 'lib/wor/authentication/controller.rb', line 48

def entity_custom_validation_renew_value(entity)
  entity_custom_validation_value(entity)
end

#entity_custom_validation_value(_entity) ⇒ Object



44
45
46
# File 'lib/wor/authentication/controller.rb', line 44

def entity_custom_validation_value(_entity)
  nil
end

#entity_payload(_entity) ⇒ Object



72
73
74
# File 'lib/wor/authentication/controller.rb', line 72

def entity_payload(_entity)
  {}
end

#find_authenticable_entity(_decoded_token) ⇒ Object



68
69
70
# File 'lib/wor/authentication/controller.rb', line 68

def find_authenticable_entity(_decoded_token)
  {}
end

#new_token_expiration_dateObject



17
18
19
# File 'lib/wor/authentication/controller.rb', line 17

def new_token_expiration_date
  Wor::Authentication.expiration_days.days.from_now.to_i
end

#token_keyObject



56
57
58
59
60
61
62
# File 'lib/wor/authentication/controller.rb', line 56

def token_key
  raise Wor::Authentication::Exceptions::SubclassMustImplementError unless defined?(Rails)
  if Rails.application.secrets.secret_key_base.blank?
    raise Wor::Authentication::Exceptions::NoKeyProvidedError
  end
  Rails.application.secrets.secret_key_base
end

#token_maximum_useful_dateObject



21
22
23
# File 'lib/wor/authentication/controller.rb', line 21

def token_maximum_useful_date
  Wor::Authentication.maximum_useful_days.days.from_now.to_i
end

#token_renew_idObject

Helpers which may be overridden



33
34
35
# File 'lib/wor/authentication/controller.rb', line 33

def token_renew_id
  Devise.friendly_token(32)
end