Permalink
Browse files

Merge pull request #1 from nilclass/master

handle deprecation of ActiveSupport::SecureRandom
  • Loading branch information...
2 parents eedf0a7 + 0be23d3 commit 69c68b37cc293efea1255bb5eb53452d0107b2c9 @robin committed Mar 5, 2012
Showing with 20 additions and 4 deletions.
  1. +2 −2 lib/couchdb_oauth2/model/client.rb
  2. +2 −2 lib/couchdb_oauth2/model/oauth2_token.rb
  3. +16 −0 lib/rack-couchdb-oauth2.rb
@@ -14,7 +14,7 @@ class Client < CouchRest::Model::Base
def setup
if self.secret.nil?
- self.secret = ActiveSupport::SecureRandom.base64(64)
+ self.secret = SecureRandom.base64(64)
end
end
@@ -27,4 +27,4 @@ def self.find_by_env(env)
client = Client.find(request.client_id)
client if client && client.secret == request.client_secret
end
-end
+end
@@ -47,11 +47,11 @@ def expired?
private
def self.generate(bytes = 64)
- ActiveSupport::SecureRandom.base64(bytes)
+ SecureRandom.base64(bytes)
end
def setup
self.token = Oauth2Token.generate
self.expires_at ||= self.default_lifetime.from_now
end
-end
+end
View
@@ -3,6 +3,22 @@
require 'couchrest_model'
require 'active_support'
+if defined? ActiveSupport::SecureRandom and not defined? SecureRandom
+ # pre 3.2 activesupport version + ruby 1.8
+ SecureRandom = ActiveSupport::SecureRandom
+elsif not defined? SecureRandom
+ if RUBY_VERSION > '1.9'
+ # ruby 1.9 brings securerandom
+ require 'securerandom'
+ else
+ begin
+ require 'securerandom'
+ rescue LoadError
+ raise LoadError, "SecureRandom not found! Use ruby 1.9, downgrade activesupport below 3.2 or install webget-securerandom gem"
+ end
+ end
+end
+
module Rack
module CouchdbOAuth2
autoload :Configuration, 'couchdb_oauth2/configuration'

0 comments on commit 69c68b3

Please sign in to comment.