Sha256: 8eab8d1ecc5def18ee40b44bfce74bee259cbd80f718123e67c6ffc0a29e69dd

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require 'doorkeeper-mongodb/compatible'

module Doorkeeper
  class AccessToken
    include DoorkeeperMongodb::Compatible

    include MongoMapper::Document

    include DoorkeeperMongodb::Mixins::MongoMapper::AccessTokenMixin

    safe
    timestamps!

    set_collection_name 'oauth_access_tokens'

    key :resource_owner_id,       ObjectId
    key :application_id,          ObjectId
    key :token,                   String
    key :refresh_token,           String
    key :previous_refresh_token,  String
    key :expires_in,              Integer
    key :revoked_at,              DateTime
    key :scopes,                  String

    def self.last
      sort(:created_at).last
    end

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

    def self.create_indexes
      ensure_index :token, unique: true
      ensure_index [[:refresh_token, 1]], unique: true, sparse: true
    end

    def self.refresh_token_revoked_on_use?
      keys.keys.include?('previous_refresh_token')
    end

    def self.order_method
      :sort
    end

    def self.created_at_desc
      :created_at.desc
    end

    def save!(options = {})
      if options.key?(:validate)
        super(options.merge(safe: options.delete(:validate)))
      else
        super
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doorkeeper-mongodb-4.0.1 lib/doorkeeper/orm/mongo_mapper/access_token.rb
doorkeeper-mongodb-4.0.0 lib/doorkeeper/orm/mongo_mapper/access_token.rb