REPP: Authentication test

This commit is contained in:
Karl Erik Õunapuu 2020-10-19 16:02:18 +03:00
parent 2a136a776f
commit 87dff41a4e
No known key found for this signature in database
GPG key ID: C9DD647298A34764
5 changed files with 58 additions and 4 deletions

View file

@ -76,7 +76,8 @@ module Repp
def basic_token
pattern = /^Basic /
header = request.headers['Authorization']
header.gsub(pattern, '') if header&.match(pattern)
header = header.gsub(pattern, '') if header&.match(pattern)
header.strip
end
def authenticate_user
@ -85,9 +86,12 @@ module Repp
return if @current_user
render(json: { errors: [{ base: ['Not authorized'] }] }, status: :unauthorized)
rescue NoMethodError
render(json: { errors: [{ base: ['Not authorized'] }] }, status: :unauthorized)
raise(ArgumentError)
rescue NoMethodError, ArgumentError
render(
json: { code: 2202, message: 'Invalid authorization information' },
status: :unauthorized
)
end
def check_ip_restriction