Sha256: 40511705d79458cd9f7e17b4ba3a8132711aca0f052bc1a6a1b8259199eb46eb

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

module Doorkeeper
  class AccessGrant < ActiveRecord::Base
    self.table_name = "#{table_name_prefix}oauth_access_grants#{table_name_suffix}".to_sym

    include AccessGrantMixin
    include ActiveModel::MassAssignmentSecurity if defined?(::ProtectedAttributes)

    belongs_to_options = {
      class_name: 'Doorkeeper::Application',
      inverse_of: :access_grants
    }

    if defined?(ActiveRecord::Base) && ActiveRecord::VERSION::MAJOR >= 5
      belongs_to_options[:optional] = true
    end

    belongs_to :application, belongs_to_options

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

    validates :token, uniqueness: true

    before_validation :generate_token, on: :create

    # We keep a volatile copy of the raw token for initial communication
    # The stored refresh_token may be mapped and not available in cleartext.
    #
    # Some strategies allow restoring stored secrets (e.g. symmetric encryption)
    # while hashing strategies do not, so you cannot rely on this value
    # returning a present value for persisted tokens.
    def plaintext_token
      if secret_strategy.allows_restoring_secrets?
        secret_strategy.restore_secret(self, :token)
      else
        @raw_token
      end
    end

    private

    # Generates token value with UniqueToken class.
    #
    # @return [String] token value
    #
    def generate_token
      @raw_token = UniqueToken.generate
      secret_strategy.store_secret(self, :token, @raw_token)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
doorkeeper-5.1.0.rc2 lib/doorkeeper/orm/active_record/access_grant.rb