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

docs: add Session v1 login example using curl [backport docs-release-5.4] #4977

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion docs/references/rest-apis/rest-session-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,63 @@ The supported workflows are the following:

4. Access the desired resources, set the XSRF token previously obtained as the value of the `X-XSRF-Token` HTTP header on each request. If a reuqest fails with error code 401, proceed to step 2.

#### Login example with `curl`

##### 1. Login with username/password and collect the session cookie

```bash
curl -k -X POST \
-H 'Content-Type: application/json' \
https://$ADDRESS/services/session/v1/login/password \
-d '{"password": "$KURA_PASS", "username": "$KURA_USER"}' -v
```

where:

- `$ADDRESS`: is the address of the Kura instance
- `$KURA_USER`: is the Kura username
- `$KURA_PASS`: is the Kura password

in the log you should find a `JSESSIONID` you'll use in subsequent reqeusts

```
...
< HTTP/1.1 200 OK
< Date: Tue, 14 Nov 2023 08:17:26 GMT
< Set-Cookie: JSESSIONID=myawesomecookie; Path=/; Secure; HttpOnly
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Content-Type: application/json
< Content-Length: 30
<
* Connection #0 to host 192.168.1.111 left intact
{"passwordChangeNeeded":false}%
```

##### 2. Retrieve the XSRF token

```bash
curl -k -X GET \
-b "JSESSIONID=myawesomecookie" \
https://$ADDRESS/services/session/v1/xsrfToken
```

in the response you'll find your XSRF token you'll need to use in subsequent requests

```
{"xsrfToken":"myawesometoken"}%
```

##### 3. Access the resource

Using the Cookie and the XSRF token you just retrieved you can access your desired resource

```bash
curl -k -X GET \
-H 'X-XSRF-Token: myawesometoken' \
-b "JSESSIONID=myawesomecookie" \
https://$ADDRESS/services/deploy/v2/
```

### Update password workflow

1. Get an XSRF token using the [GET/xsrfToken](#getxsrftoken) endpoint.
Expand Down Expand Up @@ -324,4 +381,4 @@ An object reporting a failure message.
<br>**Properties**:

* **message**: `string`
A message describing the failure.
A message describing the failure.