Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Relevant endpoint:

  • GET /authenticate/:{provider}

Accepted provider values:

  • userpass

...

Code Block
languagebash
$ curl --insecure http://localhost:9000/authenticate/userpass -vvv -XPOST --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'username=YouUsernameYourUsername' --data-urlencode 'password=YourPassword'
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> POST /authenticate/userpass HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 50
> 
* upload completely sent off: 50 out of 50 bytes
< HTTP/1.1 303 See Other
< Access-Control-Allow-Origin: *
< Location: /
< Access-Control-Allow-Headers: 
< Access-Control-Allow-Methods: *
< Access-Control-Allow-Credentials: true
< Set-Cookie: id=3656a7a78433b52522cc4cd3d1b42579e76ee46c688faa5e5c4259623dfe83531008669ad7769e600ba9d1d94b2d590710d9c9cc98f6b79728ec2cd6e043f97c6e69d5d21e0ba6f7ff0528fa310bf1f2d5002348e3c2b9957d47905ac030de57b2bd9deffd450b32ee452d4c87543f65476be709ccebb7be3b0773e8488bb496; Path=/; HTTPOnly
< Set-Cookie: PLAY_SESSION=; Expires=Mon, 06 Aug 2018 20:54:32 GMT; Path=/; HTTPOnly
< Content-Length: 0
< 
* Connection #0 to host localhost left intact

...

NOTE: You will notice that now the Set-Cookie response is settings the id cookie to an empty string - this clears your auth cookie from the browser, so you may discard the cookie that you received above as it may no longer be valid.

User API Keys

Relevant endpoints:

  • POST /api/users/keys?name={key-name}
  • GET /api/users/keys
  • GET /api/users/keys/{key-name}
  • DELETE /api/users/keys/{key-name}

These endpoints can be used to create a user-specific API key for interacting with the Clowder API.

Creating a key

To create a new API key with the given name for the currently-logged-in user:

Code Block
languagebash
$ curl --insecure 'http://localhost:9000/api/users/keys?name=testkey' -XPOST --cookie 'id=2859bdc9050ec48ea779db10bc1f54dda37e75ebc13d1c65bad0f90810159b5047df7b67dd7802b64ad7eb1dff9b4355fc67a26a9a009fffcb9de1aa5b31b7a1739553da9cfcd0d060fb11cdf96a1fadf94fd3f49afb50a4b5df6b7a9a460cbbce37d3aa012bca3b77c921f6038dd2cc618ac4f0958e33da39d5b5948c07ab13' -vvv
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> POST /api/users/keys?name=testkey HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.54.0
> Accept: */*
> Cookie: id=2859bdc9050ec48ea779db10bc1f54dda37e75ebc13d1c65bad0f90810159b5047df7b67dd7802b64ad7eb1dff9b4355fc67a26a9a009fffcb9de1aa5b31b7a1739553da9cfcd0d060fb11cdf96a1fadf94fd3f49afb50a4b5df6b7a9a460cbbce37d3aa012bca3b77c921f6038dd2cc618ac4f0958e33da39d5b5948c07ab13
> 
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: 
< Access-Control-Allow-Methods: *
< Access-Control-Allow-Credentials: true
< Content-Type: application/json; charset=utf-8
< Content-Length: 63
< 
* Connection #0 to host localhost left intact
{"name":"testkey","key":"839785b9-5e23-4a1b-92f7-259294a58aed"}

You can then attach this key as a query string parameter for all subsequent API requests, instead of needing to reauthenticate manually and attaching another cookie.

NOTE: One exception is that you cannot call the /api/users/keys endpoints using an API key, as this would cause too much security risk/confusion in case an API key were to be compromised.

For example, using a User API key to call the /api/datasets endpoint would look like this:

Code Block
languagebash
$ curl --insecure http://localhost:9000/api/datasets?key=839785b9-5e23-4a1b-92f7-259294a58aed -vvv
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> GET /api/datasets?key=839785b9-5e23-4a1b-92f7-259294a58aed HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: 
< Access-Control-Allow-Methods: *
< Access-Control-Allow-Credentials: true
< Content-Type: application/json; charset=utf-8
< Content-Length: 411
< 
* Connection #0 to host localhost left intact
[{"id":"5b4e510577c8fff0a479786c","name":"asdf","description":"","created":"Tue Jul 17 15:26:45 CDT 2018","thumbnail":"None","authorId":"5ad76e39693ea57ec7f8648a","spaces":["5b0724b277c85c0c70e371d8"]},{"id":"5ad7b5b377c8a52d73b2ac5f","name":"test_dataset","description":"","created":"Wed Apr 18 16:16:35 CDT 2018","thumbnail":"None","authorId":"5ad76e39693ea57ec7f8648a","spaces":["5ad7b4b777c8a52d73b2ac48"]}]

Retrieving Keys

To retrieve a list of all existing API keys for this user:

Code Block
languagebash
$ curl --insecure http://localhost:9000/api/users/keys --cookie 'id=2859bdc9050ec48ea779db10bc1f54dda37e75ebc13d1c65bad0f90810159b5047df7b67dd7802b64ad7eb1dff9b4355fc67a26a9a009fffcb9de1aa5b31b7a1739553da9cfcd0d060fb11cdf96a1fadf94fd3f49afb50a4b5df6b7a9a460cbbce37d3aa012bca3b77c921f6038dd2cc618ac4f0958e33da39d5b5948c07ab13' -vvv
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> GET /api/users/keys HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.54.0
> Accept: */*
> Cookie: id=2859bdc9050ec48ea779db10bc1f54dda37e75ebc13d1c65bad0f90810159b5047df7b67dd7802b64ad7eb1dff9b4355fc67a26a9a009fffcb9de1aa5b31b7a1739553da9cfcd0d060fb11cdf96a1fadf94fd3f49afb50a4b5df6b7a9a460cbbce37d3aa012bca3b77c921f6038dd2cc618ac4f0958e33da39d5b5948c07ab13
> 
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: 
< Access-Control-Allow-Methods: *
< Access-Control-Allow-Credentials: true
< Content-Type: application/json; charset=utf-8
< Content-Length: 137
< 
* Connection #0 to host localhost left intact
[{"name":"testkey","key":"22da6ca7-1c66-4612-bc4d-368f92ecf9bf","identityId":{"userId":"lambert8@illinois.edu","providerId":"userpass"}}]

To retrieve a specific API key by name:

Code Block
languagebash
$ curl --insecure http://localhost:9000/api/users/keys/testkey --cookie 'id=2859bdc9050ec48ea779db10bc1f54dda37e75ebc13d1c65bad0f90810159b5047df7b67dd7802b64ad7eb1dff9b4355fc67a26a9a009fffcb9de1aa5b31b7a1739553da9cfcd0d060fb11cdf96a1fadf94fd3f49afb50a4b5df6b7a9a460cbbce37d3aa012bca3b77c921f6038dd2cc618ac4f0958e33da39d5b5948c07ab13' -vvv
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> GET /api/users/keys/testkey HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.54.0
> Accept: */*
> Cookie: id=2859bdc9050ec48ea779db10bc1f54dda37e75ebc13d1c65bad0f90810159b5047df7b67dd7802b64ad7eb1dff9b4355fc67a26a9a009fffcb9de1aa5b31b7a1739553da9cfcd0d060fb11cdf96a1fadf94fd3f49afb50a4b5df6b7a9a460cbbce37d3aa012bca3b77c921f6038dd2cc618ac4f0958e33da39d5b5948c07ab13
> 
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: 
< Access-Control-Allow-Methods: *
< Access-Control-Allow-Credentials: true
< Content-Type: application/json; charset=utf-8
< Content-Length: 135
< 
* Connection #0 to host localhost left intact
{"name":"testkey","key":"22da6ca7-1c66-4612-bc4d-368f92ecf9bf","identityId":{"userId":"lambert8@illinois.edu","providerId":"userpass"}}

Deleting Keys

To delete an existing API key:

Code Block
languagebash
$ curl --insecure 'http://localhost:9000/api/users/keys/testkey' -XDELETE --cookie 'id=2859bdc9050ec48ea779db10bc1f54dda37e75ebc13d1c65bad0f90810159b5047df7b67dd7802b64ad7eb1dff9b4355fc67a26a9a009fffcb9de1aa5b31b7a1739553da9cfcd0d060fb11cdf96a1fadf94fd3f49afb50a4b5df6b7a9a460cbbce37d3aa012bca3b77c921f6038dd2cc618ac4f0958e33da39d5b5948c07ab13' -vvv
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9000 (#0)
> DELETE /api/users/keys/testkey HTTP/1.1
> Host: localhost:9000
> User-Agent: curl/7.54.0
> Accept: */*
> Cookie: id=2859bdc9050ec48ea779db10bc1f54dda37e75ebc13d1c65bad0f90810159b5047df7b67dd7802b64ad7eb1dff9b4355fc67a26a9a009fffcb9de1aa5b31b7a1739553da9cfcd0d060fb11cdf96a1fadf94fd3f49afb50a4b5df6b7a9a460cbbce37d3aa012bca3b77c921f6038dd2cc618ac4f0958e33da39d5b5948c07ab13
> 
< HTTP/1.1 204 No Content
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: *
< Access-Control-Allow-Headers: 
< Access-Control-Allow-Credentials: true
< Content-Length: 0
< 
* Connection #0 to host localhost left intact


Spaces

Relevant endpoints:

...