Sha256: eebb555efaa4fca71ab1ac912749a41eab9bb8ecaf7388643c2a47d69349b98f

Contents?: true

Size: 592 Bytes

Versions: 1

Compression:

Stored size: 592 Bytes

Contents

module Oa2c
  class Client
    include Mongoid::Document

    field :identifier
    field :secret
    field :redirect_uri
    field :name

    has_many :access_tokens
    has_many :refresh_tokens

    before_validation :setup, on: :create
    validates :secret, presence: true
    validates :identifier, presence: true, uniqueness: true

    private

    def setup
      self.identifier = SecureRandom.hex(16)
      generate_secret
    end

    def generate_secret
      self.secret = SecureRandom.hex(32)
    end

    def generate_secret!
      generate_secret
      save!
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oa2c-0.0.2 app/models/oa2c/client.rb