Sha256: 6bf94c879d1bc12d133970d6676cfd8c7b3008a5fadeaaa902dc0bd56b8aa963

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require 'doorkeeper/orm/mongoid4/concerns/scopes'
require 'doorkeeper-mongodb/compatible'

module Doorkeeper
  class AccessToken
    include DoorkeeperMongodb::Compatible

    include Mongoid::Document
    include Mongoid::Timestamps

    include AccessTokenMixin
    include Models::Mongoid4::Scopes

    self.store_in collection: :oauth_access_tokens

    field :resource_owner_id, type: BSON::ObjectId
    field :token, type: String
    field :refresh_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.order_method
      :order_by
    end

    def self.refresh_token_revoked_on_use?
      fields.collect { |field| field[0] }.include?('previous_refresh_token')
    end

    def self.created_at_desc
      [:created_at, :desc]
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
doorkeeper-mongodb-3.0.0 lib/doorkeeper/orm/mongoid4/access_token.rb
dd-doorkeeper-mongodb-3.0.0 lib/doorkeeper/orm/mongoid4/access_token.rb