Sha256: 49363ceb0ed1ecc16a62be67560a2eda8fba6fb5849bc2ed69cb5f7da23a750c

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

module Doorkeeper
  class AccessToken
    include Mongoid::Document
    include Mongoid::Timestamps

    include DoorkeeperMongodb::Compatible

    include DoorkeeperMongodb::Shared::Scopes
    include DoorkeeperMongodb::Mixins::Mongoid::AccessTokenMixin

    store_in collection: :oauth_access_tokens

    field :resource_owner_id, type: BSON::ObjectId
    field :token, type: String
    field :refresh_token, type: String
    field :previous_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
      %i[created_at desc]
    end
  end
end

Version data entries

6 entries across 2 versions & 1 rubygems

Version Path
doorkeeper-mongodb-4.0.1 lib/doorkeeper/orm/mongoid4/access_token.rb
doorkeeper-mongodb-4.0.1 lib/doorkeeper/orm/mongoid5/access_token.rb
doorkeeper-mongodb-4.0.1 lib/doorkeeper/orm/mongoid7/access_token.rb
doorkeeper-mongodb-4.0.0 lib/doorkeeper/orm/mongoid4/access_token.rb
doorkeeper-mongodb-4.0.0 lib/doorkeeper/orm/mongoid5/access_token.rb
doorkeeper-mongodb-4.0.0 lib/doorkeeper/orm/mongoid7/access_token.rb