ApiController: check token validity for a given admin
This commit is contained in:
parent
d576d426f4
commit
4a04f2e59f
3 changed files with 43 additions and 42 deletions
|
@ -16,6 +16,10 @@ class APIController < ApplicationController
|
|||
|
||||
protected
|
||||
|
||||
def valid_token_for_administrateur?(administrateur)
|
||||
administrateur.valid_api_token?(token)
|
||||
end
|
||||
|
||||
def default_format_json
|
||||
request.format = "json" if !request.params[:format]
|
||||
end
|
||||
|
@ -26,6 +30,10 @@ class APIController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def token
|
||||
params_token.presence || header_token
|
||||
end
|
||||
|
||||
def header_token
|
||||
received_token = nil
|
||||
authenticate_with_http_token do |token, _options|
|
||||
|
@ -33,4 +41,8 @@ class APIController < ApplicationController
|
|||
end
|
||||
received_token
|
||||
end
|
||||
|
||||
def params_token
|
||||
params[:token]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue