Module: Authbox
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/authbox.rb
Overview
This module adds support for Authbox to your Rails controller. We recommend you add it to app/controllers/application_controller.rb
like this:
require 'authbox'
class ApplicationController < ActionController::Base
include Authbox
end
Once this is included in your controller, you’ll need to add your credentials. Add them to config/application.rb like this:
config.authbox = {
:api_key => 'yourApiKey',
:secret_key => 'yourSecret'
}
That’s it! Authbox can start logging basic metadata immediately.
To get the most out of Authbox you should tell us who your users are. You do this by overriding the authbox_get_request_data() method on the controller. Here’s how you would tell Authbox about your users while using Devise:
class ApplicationController < ActionController::Base
include Authbox
def authbox_get_request_data
return {
'$user' => {
'$creationTime' => current_user.created_at,
'$userIDs' => [
{'$type' => '$email', '$key' => current_user.email}
]
}
}
end
end
Instance Method Summary collapse
-
#authbox_get_request_data ⇒ Object
Override me to return additional data for the request (like the user).
-
#authbox_log(features = {}) ⇒ Object
Report a custom action to Authbox.
-
#authbox_post_form(uri, body) ⇒ Object
Override me to inject a custom HTTP POST library.
Instance Method Details
#authbox_get_request_data ⇒ Object
Override me to return additional data for the request (like the user)
79 80 81 |
# File 'lib/authbox.rb', line 79 def authbox_get_request_data return {} end |
#authbox_log(features = {}) ⇒ Object
Report a custom action to Authbox. If this is not called during a request, an $unknown action will be logged. See the documentation for what information you can pass here in the features hash.
57 58 59 |
# File 'lib/authbox.rb', line 57 def authbox_log(features={}) return authbox_request(features, true) end |
#authbox_post_form(uri, body) ⇒ Object
Override me to inject a custom HTTP POST library
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/authbox.rb', line 63 def authbox_post_form(uri, body) req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'}) req.body = body.to_json return Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| begin http.request(req) rescue => e logger.warn 'AUTHBOX: HTTP request error: #{e}' end end end |