app/models/oauth2_token.rb in vidibus-oauth2_server-0.0.5 vs app/models/oauth2_token.rb in vidibus-oauth2_server-0.0.6

- old
+ new

@@ -1,7 +1,5 @@ -require "active_support" - class Oauth2Token include Mongoid::Document include Mongoid::Timestamps CODE_EXPIRY = 60 # Lifetime of token authorization code in seconds. @@ -20,11 +18,11 @@ index :client_id index :token index :code validates :client_id, :redirect_url, :presence => true - validates :token, :code, :uniqueness => { :allow_blank => true } + validates :token, :code, :uniqueness => {:allow_blank => true} before_create :generate_code # Returns a token by given parameters. # If +token+ is given a valid Oauth2Token will be returned. @@ -56,19 +54,19 @@ def exchange! raise Vidibus::Oauth2Server::InvalidCodeError unless code raise Vidibus::Oauth2Server::ExpiredCodeError unless code_expires_at >= Time.now self.code = nil self.code_expires_at = nil - self.token = ActiveSupport::SecureRandom.hex(60) + self.token = SecureRandom.hex(60) self.token_expires_at = Time.now + TOKEN_EXPIRY if TOKEN_EXPIRY > 0 save! return code end protected # Generate a random code def generate_code - self.code = ActiveSupport::SecureRandom.hex(60) + self.code = SecureRandom.hex(60) self.code_expires_at = Time.now + CODE_EXPIRY end end