Skip to content

Instantly share code, notes, and snippets.

@kenn
Created June 6, 2014 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kenn/3a643d09f335e24a730e to your computer and use it in GitHub Desktop.
Save kenn/3a643d09f335e24a730e to your computer and use it in GitHub Desktop.
Doorkeeper client_secret obfuscation
# config/initializers/doorkeeper.rb
Doorkeeper.configure do
client_credentials :from_obfuscated_params
end
module Doorkeeper
module OAuth
class Client
module Methods
def from_obfuscated_params(request)
client_id, client_time, client_digest = request.parameters.values_at(:client_id, :client_time, :client_digest)
if Time.at(client_time.to_f).between?(15.minutes.ago, 15.minutes.from_now) and app = Doorkeeper::Application.by_uid(client_id)
calculated_digest = OpenSSL::HMAC::hexdigest(OpenSSL::Digest::SHA1.new, app.secret, client_time)
if Rack::Utils.secure_compare(client_digest, calculated_digest)
return [client_id, app.secret]
end
end
[client_id, nil]
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment