Sha256: c1abb3a0e51d0985f5448559c199750d8606d482607f1fbe62315a420b3848c6

Contents?: true

Size: 1003 Bytes

Versions: 3

Compression:

Stored size: 1003 Bytes

Contents

module Doorkeeper
  class Application
    include Doorkeeper::OAuth::Helpers

    has_many :access_grants, dependent: :destroy, class_name: 'Doorkeeper::AccessGrant'
    has_many :access_tokens, dependent: :destroy, class_name: 'Doorkeeper::AccessToken'

    validates :name, :secret, :uid, presence: true
    validates :uid, uniqueness: true
    validates :redirect_uri, redirect_uri: true

    before_validation :generate_uid, :generate_secret, on: :create

    if ::Rails.version.to_i < 4 || defined?(ProtectedAttributes)
      attr_accessible :name, :redirect_uri
    end

    def self.model_name
      ActiveModel::Name.new(self, Doorkeeper, 'Application')
    end

    def self.authenticate(uid, secret)
      self.where(uid: uid, secret: secret).first
    end

    def self.by_uid(uid)
      self.where(uid: uid).first
    end

    private

    def generate_uid
      self.uid ||= UniqueToken.generate
    end

    def generate_secret
      self.secret ||= UniqueToken.generate
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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