Sha256: aa7766a4557f7f3686a48cda2782e148a7a965ca408043d2d2382a4188eb7368

Contents?: true

Size: 1008 Bytes

Versions: 7

Compression:

Stored size: 1008 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 :expires_at, :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

7 entries across 7 versions & 4 rubygems

Version Path
houston-oauth-plugin-0.5.1 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
panjiva-oauth-plugin-0.4.1 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.5.1 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.5.0 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-provider-0.5.0rc1 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.4.1 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb
oauth-plugin-0.4.0 lib/generators/mongoid/oauth_provider_templates/oauth_token.rb