blob: 15ddef784a35fe6a110883d8602f1890a90581a1 (
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
28
29
|
module ControllerExtension::TokenAuthentication
extend ActiveSupport::Concern
protected
def token
@token ||= authenticate_with_http_token do |token, options|
Token.find_by_token(token) || ApiToken.find_by_token(token)
end
end
def token_authenticate
@token_authenticated ||= token.authenticate if token
end
def require_token
login_required unless token_authenticate
end
def logout
super
clear_token
end
def clear_token
token.destroy if token
end
end
|