Class: OohAuth::AuthenticatingClient

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
app/models/authenticating_client/dm_authenticating_client.rb

Overview

OohAuth::AuthenticatingClient

An authenticating client is an external application which wants to use your application’s public API while authenticated as one of your users.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_for_user(user) ⇒ Object



37
38
39
40
# File 'app/models/authenticating_client/dm_authenticating_client.rb', line 37

def self.find_for_user(user)
  return [] unless user
  return all(:user_id=>user.id)
end

.new_for_user(user, attrs) ⇒ Object



31
32
33
34
35
# File 'app/models/authenticating_client/dm_authenticating_client.rb', line 31

def self.new_for_user(user, attrs)
  o = new(attrs)
  o.user = user
  return o
end

Instance Method Details

#editable_by?(user) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/authenticating_client/dm_authenticating_client.rb', line 67

def editable_by?(user)
  user.id == self.user_id
end

#generate_keys_if_not_presentObject



46
47
48
49
50
51
52
53
# File 'app/models/authenticating_client/dm_authenticating_client.rb', line 46

def generate_keys_if_not_present
  api_key_length = 15
  while self.api_key.blank? or self.class.first(:id.not=>id, :api_key=>self.api_key) do
    self.api_key = OohAuth::KeyGenerators::Alphanum.gen(api_key_length)
    api_key_length += 1
  end
  self.secret = OohAuth::KeyGenerators::Alphanum.gen(40) if secret.blank?
end

#is_webapp?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/authenticating_client/dm_authenticating_client.rb', line 42

def is_webapp?
  self.kind == "web"
end

#user=(user) ⇒ Object



63
64
65
# File 'app/models/authenticating_client/dm_authenticating_client.rb', line 63

def user=(user)
  self.user_id = user.id
end

#valid_kind?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
# File 'app/models/authenticating_client/dm_authenticating_client.rb', line 55

def valid_kind?
  if OohAuth[:client_kinds].include?(self.kind)
    return true
  else
    return false, "illegal kind"
  end
end