Class: Opro::Oauth::ClientApp

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/opro/oauth/client_app.rb

Class Method Summary collapse

Class Method Details

.authenticate(app_id, app_secret) ⇒ Object



21
22
23
# File 'app/models/opro/oauth/client_app.rb', line 21

def self.authenticate(app_id, app_secret)
  where(["app_id = ? AND app_secret = ?", app_id, app_secret]).first
end

.create_with_user_and_name(user, name) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'app/models/opro/oauth/client_app.rb', line 25

def self.create_with_user_and_name(user, name)
  client_app            = self.new
  client_app.user       = user
  client_app.name       = name
  client_app.app_id     = generate_unique_app_id
  client_app.app_secret = SecureRandom.hex(16)
  client_app.save
  client_app
end

.find_by_client_id(client_id) ⇒ Object

attr_accessible :user, :name, :app_id, :client_secret, :app_secret, :secret



17
18
19
# File 'app/models/opro/oauth/client_app.rb', line 17

def self.find_by_client_id(client_id)
  where(app_id: client_id).first
end

.generate_unique_app_id(app_id = SecureRandom.hex(16)) ⇒ Object



35
36
37
38
39
# File 'app/models/opro/oauth/client_app.rb', line 35

def self.generate_unique_app_id(app_id = SecureRandom.hex(16))
  client_app = where(:app_id => app_id)
  return app_id if client_app.blank?
  generate_unique_app_id
end