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

#authorizations ⇒ Array<Core::Models::OAuth::Authorization>

Returns the authorizations linked to the accounts this application can get the data from.

Returns:



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

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

#creator ⇒ Core::Models::Account

Returns the account that has created this application, considered its owner.

Returns:



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

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

#key ⇒ String

Returns the unique key for the application, identifying it when requesting a token for the API.

Returns:

  • (String) —

    the unique key for the application, identifying it when requesting a token for the API.



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

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

#name ⇒ String

Returns the unique name of the application, mainly used to identify and display it.

Returns:

  • (String) —

    the unique name of the application, mainly used to identify and display it.



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

field :name, type: String

#premium ⇒ Boolean

Returns a value indicating whether the application should automatically receive a token when an account is created, or not.

Returns:

  • (Boolean) —

    a value indicating whether the application should automatically receive a token when an account is created, or not.



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

field :premium, type: Boolean, default: false

Instance Method Details

#redirect_uris_values ⇒ Object

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

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


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

def redirect_uris_values
  redirect_uris.each do |uri|
    if !uri.is_a? String
      errors.add(:redirect_uris, 'type')
      break
    elsif uri.match(/\A(https?:\/\/)((([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*)|(localhost:[0-9]{2,4})\/?)\z/).nil?
      errors.add(:redirect_uris, 'format')
      break
    end
  end
end