Module: Wor::Authentication::Controller

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

Instance Method Summary collapse

Instance Method Details

#authenticate_entity(_params) ⇒ Object



60
61
62
# File 'lib/wor/authentication/controller.rb', line 60

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



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

def authentication_token
  if request.headers['Authorization'].blank?
    raise Wor::Authentication::Exceptions::MissingAuthorizationHeader
  end
  request.headers['Authorization'].split(' ').last
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



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

def entity_custom_validation_invalidate_all_value(_entity)
  nil
end

#entity_custom_validation_renew_value(entity) ⇒ Object



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

def entity_custom_validation_renew_value(entity)
  entity_custom_validation_value(entity)
end

#entity_custom_validation_value(_entity) ⇒ Object



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

def entity_custom_validation_value(_entity)
  nil
end

#entity_payload(_entity) ⇒ Object



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

def entity_payload(_entity)
  {}
end

#find_authenticable_entity(_decoded_token) ⇒ Object



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

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



52
53
54
55
56
57
58
# File 'lib/wor/authentication/controller.rb', line 52

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 overrided



29
30
31
# File 'lib/wor/authentication/controller.rb', line 29

def token_renew_id
  Devise.friendly_token(32)
end