feat(api_token): api v1 use new token
This commit is contained in:
parent
3c21090a88
commit
a47a056ee8
4 changed files with 6 additions and 9 deletions
|
@ -4,8 +4,9 @@ class APIController < ApplicationController
|
|||
protected
|
||||
|
||||
def find_administrateur_for_token(procedure)
|
||||
procedure.administrateurs.find do |administrateur|
|
||||
administrateur.valid_api_token?(api_token.token)
|
||||
api_token = APIToken.find_and_verify(authorization_bearer_token, procedure.administrateurs)
|
||||
if api_token.present? && procedure.administrateurs.include?(api_token.administrateur)
|
||||
api_token.administrateur
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -15,10 +16,6 @@ class APIController < ApplicationController
|
|||
request.format = "json" if !request.params[:format]
|
||||
end
|
||||
|
||||
def api_token
|
||||
@api_token ||= APIToken.new(authorization_bearer_token)
|
||||
end
|
||||
|
||||
def authorization_bearer_token
|
||||
params_token.presence || header_token
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe API::V1::DossiersController do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:token) { admin.renew_api_token }
|
||||
let(:token) { APIToken.generate(admin)[1] }
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, administrateur: admin) }
|
||||
let(:wrong_procedure) { create(:procedure) }
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe API::V1::ProceduresController, type: :controller do
|
||||
let!(:admin) { create(:administrateur, :with_api_token) }
|
||||
let!(:token) { admin.renew_api_token }
|
||||
let!(:token) { APIToken.generate(admin)[1] }
|
||||
|
||||
it { expect(described_class).to be < APIController }
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ describe APIController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when the admin has a token' do
|
||||
let!(:token) { admin.renew_api_token }
|
||||
let!(:token) { APIToken.generate(admin)[1] }
|
||||
|
||||
context 'and the token is given by params' do
|
||||
before { controller.params[:token] = token }
|
||||
|
|
Loading…
Reference in a new issue