Class: CFoundry::UAAClient
- Inherits:
-
Object
- Object
- CFoundry::UAAClient
- Defined in:
- lib/cfoundry/uaaclient.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#target ⇒ Object
Returns the value of attribute target.
-
#token ⇒ Object
Returns the value of attribute token.
-
#trace ⇒ Object
Returns the value of attribute trace.
Instance Method Summary collapse
- #add_user(email, password) ⇒ Object
- #authorize(username, password) ⇒ Object
- #change_password(guid, new, old) ⇒ Object
- #delete_user(guid) ⇒ Object
-
#initialize(target = "https://uaa.cloudfoundry.com", client_id = "cf") ⇒ UAAClient
constructor
A new instance of UAAClient.
- #password_score(password) ⇒ Object
- #prompts ⇒ Object
- #try_to_refresh_token! ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(target = "https://uaa.cloudfoundry.com", client_id = "cf") ⇒ UAAClient
Returns a new instance of UAAClient.
8 9 10 11 12 |
# File 'lib/cfoundry/uaaclient.rb', line 8 def initialize(target = "https://uaa.cloudfoundry.com", client_id = "cf") @target = target @client_id = client_id CF::UAA::Misc.symbolize_keys = true end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
6 7 8 |
# File 'lib/cfoundry/uaaclient.rb', line 6 def client_id @client_id end |
#target ⇒ Object
Returns the value of attribute target.
6 7 8 |
# File 'lib/cfoundry/uaaclient.rb', line 6 def target @target end |
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/cfoundry/uaaclient.rb', line 6 def token @token end |
#trace ⇒ Object
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) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cfoundry/uaaclient.rb', line 57 def add_user(email, password) wrap_uaa_errors do scim.add( :user, {:userName => email, :emails => [{:value => email}], :password => password, :name => {:givenName => email, :familyName => email} } ) end end |
#authorize(username, password) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/cfoundry/uaaclient.rb', line 20 def (username, password) @username = username @password = password wrap_uaa_errors do authenticate_with_password_grant || authenticate_with_implicit_grant end end |
#change_password(guid, new, old) ⇒ Object
35 36 37 38 39 |
# File 'lib/cfoundry/uaaclient.rb', line 35 def change_password(guid, new, old) wrap_uaa_errors do scim.change_password(guid, new, old) end end |
#delete_user(guid) ⇒ Object
70 71 72 73 74 |
# File 'lib/cfoundry/uaaclient.rb', line 70 def delete_user(guid) wrap_uaa_errors do scim.delete(:user, guid) end end |
#password_score(password) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cfoundry/uaaclient.rb', line 41 def password_score(password) wrap_uaa_errors do response = CF::UAA::Misc.password_strength(uaa_url, 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 |
#prompts ⇒ Object
14 15 16 17 18 |
# File 'lib/cfoundry/uaaclient.rb', line 14 def prompts wrap_uaa_errors do CF::UAA::Misc.server(target)[:prompts] end end |
#try_to_refresh_token! ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cfoundry/uaaclient.rb', line 76 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 |
#users ⇒ Object
29 30 31 32 33 |
# File 'lib/cfoundry/uaaclient.rb', line 29 def users wrap_uaa_errors do scim.query(:user) end end |