Sha256: c866c7b8a68df193a2f08a8bb4910f29b0790e6f0e0dc61667af7e489c59b9f7

Contents?: true

Size: 871 Bytes

Versions: 3

Compression:

Stored size: 871 Bytes

Contents

module Doorkeeper
  class AccessGrant
    include Doorkeeper::OAuth::Helpers
    include Doorkeeper::Models::Expirable
    include Doorkeeper::Models::Revocable
    include Doorkeeper::Models::Accessible
    include Doorkeeper::Models::Scopes

    belongs_to :application, class_name: 'Doorkeeper::Application', inverse_of: :access_grants

    if ::Rails.version.to_i < 4 || defined?(ProtectedAttributes)
      attr_accessible :resource_owner_id, :application_id, :expires_in, :redirect_uri, :scopes
    end

    validates :resource_owner_id, :application_id, :token, :expires_in, :redirect_uri, presence: true
    validates :token, uniqueness: true

    before_validation :generate_token, on: :create

    def self.authenticate(token)
      where(token: token).first
    end

    private

    def generate_token
      self.token = UniqueToken.generate
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
doorkeeper-1.3.1 lib/doorkeeper/models/access_grant.rb
doorkeeper-1.3.0 lib/doorkeeper/models/access_grant.rb
doorkeeper-1.2.0 lib/doorkeeper/models/access_grant.rb