Created
December 8, 2013 20:44
-
-
Save aybabtme/7863550 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clear the cookies | |
$ rm cookies.txt | |
# Create a user | |
$ curl -v -b cookies.txt -c cookies.txt -X POST 127.0.0.1:8080/api/v0.1/employees -d '{"employeeId":666, "password":"hello"}' | |
HTTP/1.1 201 Created | |
# Try querying without auth | |
$ curl -v -b cookies.txt -c cookies.txt -X GET 127.0.0.1:8080/api/v0.1/employees | |
HTTP/1.1 401 Unauthorized | |
# Get an auth session | |
$ curl -v -b cookies.txt -c cookies.txt -X POST 127.0.0.1:8080/api/v0.1/sessions -d '{"employeeId":666, "password":"hello"}' | |
HTTP/1.1 201 Created | |
Set-Cookie: session=MTM4NjUzNTA1MnxtdEM2RDZ0VEVBNXdMNXVXc2ZqanFCR1FsYlJ4T01QR3hQMGhuX3N3djROckMzRUhHbmhKTy1OaU5jSXp3N0kzWlZHTDZ0Y3ZYbkhDdkk1Ukh1YjN84aGW7_jFWeP49lmul2ekN1QEgQkj9Yp6ZNtWSU1LCtA=; Path=/; Max-Age=86400000000000 | |
# Query with auth | |
# Header has `Cookie: session=MTM4NjUzNTA1MnxtdEM2RDZ0VEVBNXdMNXVXc2ZqanFCR1FsYlJ4T01QR3hQMGhuX3N3djROckMzRUhHbmhKTy1OaU5jSXp3N0kzWlZHTDZ0Y3ZYbkhDdkk1Ukh1YjN84aGW7_jFWeP49lmul2ekN1QEgQkj9Yp6ZNtWSU1LCtA=` | |
$ curl -v -b cookies.txt -c cookies.txt -X GET 127.0.0.1:8080/api/v0.1/employees | |
HTTP/1.1 200 OK | |
[{"employeeId":666,"wardId":0,"firstName":"","lastName":"","email":"","roles":null}] | |
# Delete the session | |
$ curl -v -b cookies.txt -c cookies.txt -X DELETE 127.0.0.1:8080/api/v0.1/sessions | |
HTTP/1.1 204 No Content | |
Set-Cookie: session=MTM4NjUzNTIxN3w1SUZwYnQzb2xNLTlfdG8zRzJfdlNxLWstbmR0TVNPQ1hfNWdrRUsySzY2bkNsZnd85zDQe6iXAaKyGaMx5JS4DgohnmLkwD29MUT3fhPqaLE=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 UTC; Max-Age=0 | |
# Try querying the API without auth session | |
$ curl -v -b cookies.txt -c cookies.txt -X GET 127.0.0.1:8080/api/v0.1/employees | |
HTTP/1.1 401 Unauthorized | |
# Try to create a new session | |
$ curl -v -b cookies.txt -c cookies.txt -X POST 127.0.0.1:8080/api/v0.1/sessions -d '{"employeeId":666, "password":"hello"}' | |
HTTP/1.1 201 Created | |
Set-Cookie: session=MTM4NjUzNTMzM3xzZG54dkp6YkFCTW5SYmRGcWJZSGpfajBLRmFfeDBJNkJNRXY4NUxydjZ4dUw2SEUtSDFlWC1qdFFWay1OcmJUdjZDUmpNb2tVVl9hbUMxb3A2cE98WVx12tRNNhdvEPRRimGiF4lEDjlJTl0JLAMMuwBKpFs=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 UTC; Max-Age=0 | |
# Try to query API with auth | |
$ curl -v -b cookies.txt -c cookies.txt -X GET 127.0.0.1:8080/api/v0.1/employees | |
HTTP/1.1 401 Unauthorized | |
{"errorCode":401,"errorMessage":"Authentication required"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2013/12/08 15:36:24 Listening on :8080 | |
127.0.0.1 - - [08/Dec/2013:15:36:34 -0500] "POST /api/v0.1/employees HTTP/1.1" 201 0 | |
2013/12/08 15:37:06 401: No employee in cookie, answered 'Authentication required' | |
127.0.0.1 - - [08/Dec/2013:15:37:06 -0500] "GET /api/v0.1/employees HTTP/1.1" 401 59 | |
2013/12/08 15:37:32 Saved session cookie, values: map[emplID:666] | |
127.0.0.1 - - [08/Dec/2013:15:37:32 -0500] "POST /api/v0.1/sessions HTTP/1.1" 201 0 | |
127.0.0.1 - - [08/Dec/2013:15:39:13 -0500] "GET /api/v0.1/employees HTTP/1.1" 200 85 | |
2013/12/08 15:40:17 Deleting cookie from values: map[emplID:666] | |
2013/12/08 15:40:17 After deleting cookie, values: map[] | |
127.0.0.1 - - [08/Dec/2013:15:40:17 -0500] "DELETE /api/v0.1/sessions HTTP/1.1" 204 0 | |
2013/12/08 15:41:32 401: No employee in cookie, answered 'Authentication required' | |
127.0.0.1 - - [08/Dec/2013:15:41:32 -0500] "GET /api/v0.1/employees HTTP/1.1" 401 59 | |
2013/12/08 15:42:13 Saved session cookie, values: map[emplID:666] | |
127.0.0.1 - - [08/Dec/2013:15:42:13 -0500] "POST /api/v0.1/sessions HTTP/1.1" 201 0 | |
2013/12/08 15:42:59 401: No employee in cookie, answered 'Authentication required' | |
127.0.0.1 - - [08/Dec/2013:15:42:59 -0500] "GET /api/v0.1/employees HTTP/1.1" 401 59 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment