summaryrefslogtreecommitdiff
path: root/app/controllers/controller_extension/token_authentication.rb
blob: b0ed624316545f34a037afc914068a1feadb8e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module ControllerExtension::TokenAuthentication
  extend ActiveSupport::Concern

  def token
    @token ||= authenticate_with_http_token do |token, options|
      Token.find_by_token(token)
    end
  end

  def token_authenticate
    @token_authenticated ||= token.authenticate if token
  end

  def require_token
    access_denied unless token_authenticate
  end

  def logout
    super
    clear_token
  end

  def clear_token
    token.destroy if token
  end
end