Class: Oauth2::Provider::OauthClient

Inherits:
ModelBase
  • Object
show all
Defined in:
app/models/oauth2/provider/oauth_client.rb

Constant Summary

Constants inherited from ModelBase

ModelBase::CONVERTORS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ModelBase

all, #assign_attributes, columns, compact_name, count, create, create!, #datasource, datasource, datasource=, default_datasource, #destroy, find, find_all_with, find_by_id, find_one, #initialize, #new_record?, #reload, #save, #save!, size, #to_param, #to_xml, transaction, #transaction, #update_attributes, #update_from_dto, validates_uniqueness_of

Constructor Details

This class inherits a constructor from Oauth2::Provider::ModelBase

Class Method Details

.model_nameObject



25
26
27
# File 'app/models/oauth2/provider/oauth_client.rb', line 25

def self.model_name
  ActiveSupport::ModelName.new('OauthClient')
end

Instance Method Details

#before_createObject



37
38
39
40
# File 'app/models/oauth2/provider/oauth_client.rb', line 37

def before_create
  self.client_id = ActiveSupport::SecureRandom.hex(32)
  self.client_secret = ActiveSupport::SecureRandom.hex(32)
end

#before_destroyObject



42
43
44
45
# File 'app/models/oauth2/provider/oauth_client.rb', line 42

def before_destroy
  oauth_tokens.each(&:destroy)
  oauth_authorizations.each(&:destroy)
end

#before_saveObject



47
48
49
50
# File 'app/models/oauth2/provider/oauth_client.rb', line 47

def before_save
  self.name.strip! if self.name
  self.redirect_uri.strip! if self.redirect_uri
end

#create_authorization_for_user_id(user_id) ⇒ Object



18
19
20
21
22
23
# File 'app/models/oauth2/provider/oauth_client.rb', line 18

def create_authorization_for_user_id(user_id)
  oauth_authorizations.each do |authorization|
    authorization.destroy if authorization.user_id == user_id
  end
  OauthAuthorization.create!(:user_id => user_id, :oauth_client_id => id)
end

#create_token_for_user_id(user_id) ⇒ Object



14
15
16
# File 'app/models/oauth2/provider/oauth_client.rb', line 14

def create_token_for_user_id(user_id)
  OauthToken.create!(:user_id => user_id, :oauth_client_id => id)
end

#oauth_authorizationsObject



33
34
35
# File 'app/models/oauth2/provider/oauth_client.rb', line 33

def oauth_authorizations
  OauthAuthorization.find_all_with(:oauth_client_id, id)
end

#oauth_tokensObject



29
30
31
# File 'app/models/oauth2/provider/oauth_client.rb', line 29

def oauth_tokens
  OauthToken.find_all_with(:oauth_client_id, id)
end