Module: Brainpickin::RemoteAuthHelper

Defined in:
lib/brainpickin_remote_auth.rb

Overview

Provides the method that generates the auth url. Mixin where required.

Instance Method Summary collapse

Instance Method Details

#brainpickin_remote_auth_url(user_or_params) ⇒ Object

Takes a hash of parameters and generates the hashed auth url. The hash must include the :name and :email for the user. See: my.brainpickin.com/api/remote_authentication for a list of all of the parameters.

If the :timestamp is not provided, Time.now will be used. If an :external_id is provided, then the :hash will be generated.

As a convenience, a user object can be passed instead, but must respond_to? at least :email and :name. The :id of the user object will be used as the :external_id.



43
44
45
46
47
48
49
50
# File 'lib/brainpickin_remote_auth.rb', line 43

def brainpickin_remote_auth_url(user_or_params)
  params = user_or_params.is_a?(Hash) ? user_or_params : user_to_params(user_or_params)
  validate_params(params)
  params[:timestamp] = Time.now.utc.to_i unless params[:timestamp]
  params[:hash] = params[:external_id] ? generate_hash(Brainpickin::RemoteAuth.token, params) : ''

  "#{Brainpickin::RemoteAuth.auth_url}?#{params.to_query}"
end