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



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

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



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

def self.create_with_user_and_name(user, name)
  create(:user => user, :name => name, :app_id => generate_unique_app_id, :app_secret => SecureRandom.hex(16))
end

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



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

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