Sha256: 58116f17181111e43d66437c88e5559617f4a7a8b2125d8925120c30e09e8933

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

module Devise::Oauth
  class Client < ActiveRecord::Base
    def self.client_ownable?
      Devise::Oauth.client_owner.constantize.devise_modules.include? :client_ownable
    end

    belongs_to :owner, class_name: Devise::Oauth.client_owner if self.client_ownable?

    has_many :access_tokens,  class_name: "Devise::Oauth::AccessToken",   dependent: :destroy
    has_many :authorizations, class_name: "Devise::Oauth::Authorization", dependent: :destroy
    has_many :accesses,       class_name: "Devise::Oauth::Access",        dependent: :destroy

    validates :name,     presence: true
    validates :owner_id, presence: true
    validates :site_uri, presence: true

    serialize :redirect_uris, Array

    include Devise::Oauth::Scopable
    include Devise::Oauth::Blockable

    def block!
      super
      AccessToken.block_client!  id
      Authorization.block_client! id
    end

    before_create :generate_identifier
    before_create :generate_secret

    def granted!
      self.class.update_counters(id, granted_times: 1)
    end

    def revoked!
      self.class.update_counters(id, revoked_times: 1)
    end

    private

    def generate_identifier
      self.identifier = Devise::Oauth.friendly_token
    end

    def generate_secret
      self.secret = Devise::Oauth.friendly_token
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
devise_oauth-3.0.3 app/models/devise/oauth/client.rb
devise_oauth-3.0.2 app/models/devise/oauth/client.rb
devise_oauth-3.0.1 app/models/devise/oauth/client.rb
devise_oauth-3.0.0 app/models/devise/oauth/client.rb