class Plasticine::Authentication

Public Class Methods

new(request_url, params={}) click to toggle source
# File lib/plasticine/authentication.rb, line 6
def initialize(request_url, params={})
  @request_url = request_url
  @params = params
end

Public Instance Methods

expired?() click to toggle source
# File lib/plasticine/authentication.rb, line 11
def expired?
  @params[:timestamp] and Time.parse(@params[:timestamp]) + 12.hours < Time.now
end
tokenize() click to toggle source
# File lib/plasticine/authentication.rb, line 19
def tokenize
  OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, token_key, filtered_url)
end
valid_token?() click to toggle source
# File lib/plasticine/authentication.rb, line 15
def valid_token?
  @params[:token] == tokenize
end

Private Instance Methods

compacted_params() click to toggle source
# File lib/plasticine/authentication.rb, line 26
def compacted_params
  ps = @params.respond_to?(:to_unsafe_h) ? @params.to_unsafe_h : @params
  ps.map{ |k,v| "#{k}#{v}" if not reserved_params.include?(k.to_s) }.join
end
filtered_url() click to toggle source
# File lib/plasticine/authentication.rb, line 31
def filtered_url
  url = @request_url.split('?').first.rpartition('/').first + compacted_params
  url.chars.sort.join.gsub('/', '')
end
reserved_params() click to toggle source
# File lib/plasticine/authentication.rb, line 36
def reserved_params
  ['action', 'class', 'controller', 'format', 'from', 'nature', 'step', 'to', 'token', 'tools', 'update_every', 'version']
end
token_key() click to toggle source
# File lib/plasticine/authentication.rb, line 40
def token_key
  Rails.application.config.secret_key_base
end