Sha256: 90e65a68a5389d054fc8ce144a192a7ee269b91899b1bc73409aaad10de94d60

Contents?: true

Size: 1.22 KB

Versions: 17

Compression:

Stored size: 1.22 KB

Contents

require 'doorkeeper/models/mongoid/revocable'
require 'doorkeeper/models/mongoid/scopes'

module Doorkeeper
  class AccessToken
    include Mongoid::Document
    include Mongoid::Timestamps
    include Doorkeeper::Models::Mongoid::Revocable
    include Doorkeeper::Models::Mongoid::Scopes

    self.store_in collection: :oauth_access_tokens

    field :resource_owner_id, :type => Moped::BSON::ObjectId
    field :token, :type => String
    field :expires_in, :type => Integer
    field :revoked_at, :type => DateTime

    index({ token: 1 }, { unique: true })
    index({ refresh_token: 1 }, { unique: true, sparse: true })

    def self.delete_all_for(application_id, resource_owner)
      where(:application_id => application_id,
            :resource_owner_id => resource_owner.id).delete_all
    end
    private_class_method :delete_all_for

    def self.last_authorized_token_for(application, resource_owner_id)
      where(:application_id => application.id,
            :resource_owner_id => resource_owner_id,
            :revoked_at => nil).
      order_by([:created_at, :desc]).
      limit(1).
      first
    end
    private_class_method :last_authorized_token_for

    def refresh_token
      self[:refresh_token]
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
doorkeeper-1.0.0 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-1.0.0.rc2 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-1.0.0.rc1 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.7.4 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.7.3 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.7.2 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.7.1 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.7.0 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.6.7 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.6.6 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.6.5 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.6.4 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.6.3 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.6.2 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.6.1 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.6.0 lib/doorkeeper/models/mongoid3/access_token.rb
doorkeeper-0.6.0.rc1 lib/doorkeeper/models/mongoid3/access_token.rb