Class: Core::Models::OAuth::Application

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/core/models/oauth/application.rb

Overview

An application is what is referred to in the OAuth2.0 RFC as a client, wanting to access private informations about the user.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorizationsArray<Core::Models::OAuth::Authorization>



30
# File 'lib/core/models/oauth/application.rb', line 30

has_many :authorizations, class_name: 'Core::Models::OAuth::Authorization', inverse_of: :application

#creatorCore::Models::Account



27
# File 'lib/core/models/oauth/application.rb', line 27

belongs_to :creator, class_name: 'Core::Models::Account', inverse_of: :applications

#keyString



17
# File 'lib/core/models/oauth/application.rb', line 17

field :key, type: String, default: ->{ SecureRandom.hex }

#nameString



14
# File 'lib/core/models/oauth/application.rb', line 14

field :name, type: String

#premiumBoolean



20
# File 'lib/core/models/oauth/application.rb', line 20

field :premium, type: Mongoid::Boolean, default: false

Instance Method Details

#redirect_uris_valuesObject

Checks the URIs to get sure they are correct, a URI is correct if :

  • it is a string
  • it has a correct URL format.


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/core/models/oauth/application.rb', line 46

def redirect_uris_values
  redirect_uris.each do |uri|
    if !uri.is_a? String
      errors.add(:redirect_uris, 'type')
      break
    elsif uri.match(/\Ahttps?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)\z/).nil?
      errors.add(:redirect_uris, 'format')
      break
    end
  end
end