Class: CFoundry::UAAClient

Inherits:
Object
  • Object
show all
Defined in:
lib/cfoundry/uaaclient.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, client_id = "cf", options = {}) ⇒ UAAClient

Returns a new instance of UAAClient.



8
9
10
11
12
13
# File 'lib/cfoundry/uaaclient.rb', line 8

def initialize(target, client_id = "cf", options = {})
  @target = target
  @client_id = client_id
  @client_secret = options[:client_secret]
  @uaa_info_client = uaa_info_client_for(target)
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



6
7
8
# File 'lib/cfoundry/uaaclient.rb', line 6

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



6
7
8
# File 'lib/cfoundry/uaaclient.rb', line 6

def client_secret
  @client_secret
end

#targetObject

Returns the value of attribute target.



6
7
8
# File 'lib/cfoundry/uaaclient.rb', line 6

def target
  @target
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/cfoundry/uaaclient.rb', line 6

def token
  @token
end

#traceObject

Returns the value of attribute trace.



6
7
8
# File 'lib/cfoundry/uaaclient.rb', line 6

def trace
  @trace
end

Instance Method Details

#add_user(email, password, options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cfoundry/uaaclient.rb', line 62

def add_user(email, password, options = {})
  wrap_uaa_errors do
    scim.add(
      :user,
      {:userName => email,
        :emails => [{:value => email}],
        :password => password,
        :name => {:givenName => options[:givenName] || email,
                  :familyName => options[:familyName] || email}
      }
    )
  end
end

#authorize(credentials) ⇒ Object



21
22
23
24
25
26
# File 'lib/cfoundry/uaaclient.rb', line 21

def authorize(credentials)
  wrap_uaa_errors do
    authenticate_with_password_grant(credentials) ||
      authenticate_with_implicit_grant(credentials)
  end
end

#change_password(guid, new, old) ⇒ Object



40
41
42
43
44
# File 'lib/cfoundry/uaaclient.rb', line 40

def change_password(guid, new, old)
  wrap_uaa_errors do
    scim.change_password(guid, new, old)
  end
end

#delete_user(guid) ⇒ Object



76
77
78
79
80
# File 'lib/cfoundry/uaaclient.rb', line 76

def delete_user(guid)
  wrap_uaa_errors do
    scim.delete(:user, guid)
  end
end

#password_score(password) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cfoundry/uaaclient.rb', line 46

def password_score(password)
  wrap_uaa_errors do
    response = uaa_info_client_for(uaa_url).password_strength(password)

    required_score = response[:requiredScore] || 0
    case (response[:score] || 0)
      when 10 then
        :strong
      when required_score..9 then
        :good
      else
        :weak
    end
  end
end

#promptsObject



15
16
17
18
19
# File 'lib/cfoundry/uaaclient.rb', line 15

def prompts
  wrap_uaa_errors do
    @uaa_info_client.server[:prompts]
  end
end

#try_to_refresh_token!Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/cfoundry/uaaclient.rb', line 82

def try_to_refresh_token!
  wrap_uaa_errors do
    begin
      token_info = token_issuer.refresh_token_grant(token.refresh_token)
      self.token = AuthToken.from_uaa_token_info(token_info)
    rescue CF::UAA::TargetError
      self.token
    end
  end
end

#user(guid) ⇒ Object



28
29
30
31
32
# File 'lib/cfoundry/uaaclient.rb', line 28

def user(guid)
  wrap_uaa_errors do
    scim.get(:user, guid)
  end
end

#usersObject



34
35
36
37
38
# File 'lib/cfoundry/uaaclient.rb', line 34

def users
  wrap_uaa_errors do
    scim.query(:user)
  end
end