Commit a2031b42 by ivan Lan

Allow to have a custom auth header name

parent ddf4d010
......@@ -96,11 +96,17 @@ module RailsApiAuthentication
end
def auth!(request)
token = request.env["HTTP_#{self.to_s.upcase}_TOKEN"] || request.env["#{self.to_s.upcase}_TOKEN"]
token = request.env["HTTP_#{token_key}_TOKEN"] || request.env["#{token_key}_TOKEN"]
user = auth(token)
user.nil? ? raise(UserError.new(401, '-1', 'Unauthorized')) : user
end
attr_writer :token_key
def token_key
@token_key ||= self.to_s
end
def register(name, password, attrs={})
raise(UserError.new(400, '-1', 'password is blank')) if password.blank?
valid! name, attrs.delete(@valid_key)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment