Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curl example to update password on UAA #252

Closed
jabrena opened this issue Nov 10, 2015 · 3 comments
Closed

Curl example to update password on UAA #252

jabrena opened this issue Nov 10, 2015 · 3 comments

Comments

@jabrena
Copy link

jabrena commented Nov 10, 2015

Good morning,

I am trying to update a Password account using REST, but I receive the following error:

<p><b>message</b> <u></u></p>
<p><b>description</b> 
<u>The request sent by the c lient was syntactically incorrect.</u>
</p>
<HR size=\"1\" noshade=\"noshade\">
<h3 
Apache Tomcat/7.0.55</h3></body></html>" was thrown, throw an Error :)

Reading the documentation, I need an account with privilegies to update password and the account used:

{ value: '1b48d072-6715-40a4-b01c-f4f8ede67db9', display: 'password.write', type: 'DIRECT' },

Besides the JSON body to send in the request is OK:

var accountPassword = "123456"
uaa_options = { "schemas":["urn:scim:schemas:core:1.0"], 
"password": accountPassword };

But I receive the same error for the request:

var url = this.UAA_API_URL + "/Users/" + uaa_guid + "/password";
    var options = {
        method: 'PUT',
        url: url,
        headers: {
            Accept: 'application/json',
            Authorization: token_type + ' ' + access_token
        },
        json: uaa_options
    };

https://github.com/prosociallearnEU/cf-nodejs-client/blob/master/lib/model/UsersUAA.js#L51-L75
https://github.com/prosociallearnEU/cf-nodejs-client/blob/master/test/lib/model/UserUAATests.js#L142-L192

Where is my syntax error?

If I get a curl example, I could try to find my problem.
The documentation to update a password is not clear for me.

Can you help me?

Juan Antonio

@cf-gitbot
Copy link

We have created an issue in Pivotal Tracker to manage this. You can view the current status of your issue at: https://www.pivotaltracker.com/story/show/107801248.

@paulcwarren
Copy link
Member

Hi Juan,

We updated the docs to use a more standard format and aded a curl example. If you require further clarification then you can use the following test case as a guide:-

https://github.com/cloudfoundry/uaa/blob/master/uaa/src/test/java/org/cloudfoundry/identity/uaa/scim/endpoints/ScimUserEndpointsMockMvcTests.java#L168

Many thanks
_Paul

@jabrena
Copy link
Author

jabrena commented Dec 16, 2015

Good morning Paul,

Sorry, I continue with my problems to update the password, I have refactored the testcase and now, I update the password using the token from the user who I want to update, but when I execute the request, I receive the same error.

I am not sure if the problem is about the user permissions but I think that the request is Ok.

Test case:
https://github.com/prosociallearnEU/cf-nodejs-client/blob/master/test/lib/model/uaa/UserUAATests.js#L142-L205

Pseudocode:

  1. Add a new user:

Request:

            var accountName = "user" + randomInt(1, 1000);
            var accountPassword = "123456";
            var uaa_guid = null;
            var user_id = null;
            var uaa_options = {
                schemas: ["urn:scim:schemas:core:1.0"],
                userName: accountName,
                name: {
                    formatted: accountName,
                    familyName: accountName,
                    givenName: accountName
                },
                emails: [
                    {
                      "value":"user@example.com",
                      "type":"work"
                    }
                  ],
                password: accountPassword,
            };

Response from uaa server: OK

{ id: '7f21b611-4059-4fe4-b8cb-6b2da7b17c90',
  meta:
   { version: 0,
     created: '2015-12-16T09:40:19.422Z',
     lastModified: '2015-12-16T09:40:19.422Z' },
  userName: 'user274',
  name: { familyName: 'user274', givenName: 'user274' },
  emails: [ { value: 'user@example.com' } ],
  groups:
   [ { value: 'e08cbc0b-a032-4c03-86ed-03e6b33a585e',
       display: 'notification_preferences.write',
       type: 'DIRECT' },
     { value: 'c6032d43-5eb6-4719-8ff5-5ec3b6bf7cf8',
       display: 'approvals.me',
       type: 'DIRECT' },
     { value: '084442d8-fa2c-416e-9163-9f26ea928316',
       display: 'notification_preferences.read',
       type: 'DIRECT' },
     { value: 'dead2fa1-02f3-46a4-9072-5315e7c692ac',
       display: 'cloud_controller.read',
       type: 'DIRECT' },
     { value: '7b545c0e-7cd4-4ca3-87f6-0458594f928d',
       display: 'openid',
       type: 'DIRECT' },
     { value: '7b2e9bac-606f-4e03-87a8-f8121616521f',
       display: 'cloud_controller_service_permissions.read',
       type: 'DIRECT' },
     { value: '1b48d072-6715-40a4-b01c-f4f8ede67db9',
       display: 'password.write',
       type: 'DIRECT' },
     { value: '8605ea52-a0d5-4801-91c8-cf8cb6f79c4b',
       display: 'cloud_controller.write',
       type: 'DIRECT' },
     { value: '156bb655-4ef4-4068-a0ed-fa877e03eb51',
       display: 'uaa.user',
       type: 'DIRECT' },
     { value: 'e7ed28ab-3a6e-429a-9b4b-fcf921e1b5dd',
       display: 'oauth.approvals',
       type: 'DIRECT' },
     { value: '52ed4af3-1a7b-413d-9189-ab2e2b750d8b',
       display: 'scim.me',
       type: 'DIRECT' } ],
  approvals: [],
  active: true,
  verified: false,
  origin: 'uaa',
  schemas: [ 'urn:scim:schemas:core:1.0' ] }

In the documentation:
https://github.com/cloudfoundry/uaa/blob/master/docs/UAA-APIs.rst#change-password-put-users-id-password

I need this permissions:

scope = password.write
aud = password

Does the new user the right permissions?

  1. Login with the new user to get a token from the user to update the password.
  2. Update password:
{ method: 'PUT',
  url: 'https://uaa.MY_IP.xip.io/Users/7f21b611-4059-4fe4-b8cb-6b2da7b17c
90/password',
  headers:
   { Accept: 'application/json',
     Authorization: 'bearer eyJhbGciOi...aIY' },
  json:
   { schemas: [ 'urn:scim:schemas:core:1.0' ],
     password: '123456',
     oldPassword: '123456' } }

The exception is the same:

<html><head><title>Apache Tomcat/7.0.55 - Error report</title><style><!--H1 {fon
t-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:
22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525
D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;backgro
und-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;col
or:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:w
hite;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;backgroun
d:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR
{color : #525D76;}--></style> </head><body><h1>HTTP Status 400 - </h1><HR size="
1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></
p><p><b>description</b> <u>The request sent by the client was syntactically inco
rrect.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.55</h3></body
></html>

But I fixed 2 mistakes in relation to previous test:

  • I update the password with the same user, so the token is about the user who I want to update the password.
  • The request use id field not uaa_guid

Juan Antonio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants