Class: CFoundry::UAAClient

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

Constant Summary

Constants inherited from BaseClient

BaseClient::LOG_LENGTH

Instance Attribute Summary collapse

Attributes inherited from BaseClient

#backtrace, #log

Instance Method Summary collapse

Methods inherited from BaseClient

#request_path, #token_data

Constructor Details

#initialize(target = "https://uaa.cloudfoundry.com", client_id = "vmc") ⇒ UAAClient

Returns a new instance of UAAClient.



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

def initialize(
    target = "https://uaa.cloudfoundry.com",
    client_id = "vmc")
  @target = target
  @client_id = client_id
  @redirect_uri = "https://uaa.cloudfoundry.com/redirect/vmc"
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

#redirect_uriObject

Returns the value of attribute redirect_uri.



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

def redirect_uri
  @redirect_uri
end

#targetObject

Returns the value of attribute target.



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

def target
  @target
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#traceObject

Returns the value of attribute trace.



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

def trace
  @trace
end

Instance Method Details

#authorize(credentials) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cfoundry/uaaclient.rb', line 19

def authorize(credentials)
  query = {
    :client_id => @client_id,
    :response_type => "token",
    :redirect_uri => @redirect_uri
  }

  auth =
    post(
      { :credentials => credentials },
      "oauth", "authorize",
      :return_response => true,
      :content => :form,
      :accept => :json,
      :params => query)

  case auth
  when Net::HTTPRedirection
    extract_token(auth["location"])
  else
    json = parse_json(auth.body)
    raise CFoundry::Denied.new(
      auth.code.to_i,
      json[:error_description])
  end
end

#change_password(guid, new, old) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/cfoundry/uaaclient.rb', line 50

def change_password(guid, new, old)
  put(
    { :schemas => ["urn:scim:schemas:core:1.0"],
      :password => new,
      :oldPassword => old
    },
    "User", guid, "password",
    :content => :json)
end

#promptsObject



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

def prompts
  get("login", :accept => :json)[:prompts]
end

#usersObject



46
47
48
# File 'lib/cfoundry/uaaclient.rb', line 46

def users
  get("Users", :accept => :json)
end