Sha256: 0da1858f986514a13d10793fa050f5bed0175efc4894e1284039a7eb0c657710

Contents?: true

Size: 1006 Bytes

Versions: 12

Compression:

Stored size: 1006 Bytes

Contents

class OauthToken
  include Mongoid::Document
  include Mongoid::Timestamps

  field :token, :type => String
  field :secret, :type => String
  field :callback_url, :type => String
  field :verifier, :type => String
  field :scope, :type => String
  field :authorized_at, :type => Time
  field :invalidated_at, :type => Time
  field :valid_to, :type => Time

  index :token, :unique => true

  referenced_in :user
  referenced_in :client_application

  validates_uniqueness_of :token
  validates_presence_of :client_application, :token
  before_validation :generate_keys, :on => :create

  def invalidated?
    !invalidated_at.nil?
  end

  def invalidate!
    update_attribute(:invalidated_at, Time.now)
  end

  def authorized?
    !authorized_at.nil? && !invalidated?
  end

  def to_query
    "oauth_token=#{token}&oauth_token_secret=#{secret}"
  end

  protected
  def generate_keys
    self.token = OAuth::Helper.generate_key(40)[0,40]
    self.secret = OAuth::Helper.generate_key(40)[0,40]
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
oauth-plugin-0.4.0.rc2 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.4.0.rc1 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.4.0.pre7 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.4.0.pre6 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.4.0.pre5 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
insrc-oauth-plugin-0.4.0.pre6 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
insrc-oauth-plugin-0.4.0.pre5 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
le1t0-oauth-plugin-0.4.0.pre4.001 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.4.0.pre4 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.4.0.pre3 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.4.0.pre2 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.4.0.pre1 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb