Sha256: e9b94103a0f2456e230937b01ff23242b9e5f7272a67ff7caefaf14d703abe66

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'securerandom'
module Osso
  module Models
    class OauthClient < ActiveRecord::Base
      has_many :access_tokens
      has_many :refresh_tokens
      has_many :identity_providers
      has_many :redirect_uris

      before_validation :generate_secrets, on: :create
      validates :name, :secret, presence: true
      validates :identifier, presence: true, uniqueness: true

      def primary_redirect_uri
        redirect_uris.find(&:primary)
      end

      def redirect_uri_values
        redirect_uris.map(&:uri)
      end

      def generate_secrets
        self.identifier = SecureRandom.hex(16)
        self.secret = SecureRandom.hex(32)
      end
    end
  end
end

# == Schema Information
#
# Table name: oauth_clients
#
#  id         :uuid             not null, primary key
#  name       :string           not null
#  secret     :string           not null
#  identifier :string           not null
#  created_at :datetime         not null
#  updated_at :datetime         not null
#
# Indexes
#
#  index_oauth_clients_on_identifier  (identifier) UNIQUE
#

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
osso-0.0.3.16 lib/osso/models/oauth_client.rb
osso-0.0.3.15 lib/osso/models/oauth_client.rb
osso-0.0.3.14 lib/osso/models/oauth_client.rb
osso-0.0.3.13 lib/osso/models/oauth_client.rb