2016-01-14 20:00:50 +01:00
|
|
|
= Basic authorization example using REST
|
2013-01-30 00:30:05 +04:00
|
|
|
|
2013-10-22 09:14:32 +02:00
|
|
|
To try this example, you need GNU `make` and `git` in your PATH.
|
2013-01-30 00:30:05 +04:00
|
|
|
|
2016-01-14 20:00:50 +01:00
|
|
|
To build and run the example, use the following command:
|
2013-01-30 00:30:05 +04:00
|
|
|
|
2016-01-14 20:00:50 +01:00
|
|
|
[source,bash]
|
|
|
|
$ make run
|
2013-09-07 16:18:51 +02:00
|
|
|
|
2016-01-14 20:00:50 +01:00
|
|
|
Then point your browser to http://localhost:8080
|
2013-09-07 16:18:51 +02:00
|
|
|
|
2016-01-14 20:00:50 +01:00
|
|
|
== Example output
|
2013-09-07 16:18:51 +02:00
|
|
|
|
|
|
|
Request with no authentication:
|
2013-01-30 00:30:05 +04:00
|
|
|
|
2016-01-14 20:00:50 +01:00
|
|
|
[source,bash]
|
|
|
|
----
|
2013-01-30 00:30:05 +04:00
|
|
|
$ curl -i http://localhost:8080
|
|
|
|
HTTP/1.1 401 Unauthorized
|
|
|
|
connection: keep-alive
|
|
|
|
server: Cowboy
|
|
|
|
date: Sun, 20 Jan 2013 14:10:27 GMT
|
|
|
|
content-length: 0
|
2013-09-07 16:18:51 +02:00
|
|
|
www-authenticate: Basic realm="cowboy"
|
2016-01-14 20:00:50 +01:00
|
|
|
----
|
2013-01-30 00:30:05 +04:00
|
|
|
|
2013-09-07 16:18:51 +02:00
|
|
|
Request with authentication:
|
|
|
|
|
2016-01-14 20:00:50 +01:00
|
|
|
[source,bash]
|
|
|
|
----
|
2013-01-30 00:30:05 +04:00
|
|
|
$ curl -i -u "Alladin:open sesame" http://localhost:8080
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
connection: keep-alive
|
|
|
|
server: Cowboy
|
|
|
|
date: Sun, 20 Jan 2013 14:11:12 GMT
|
|
|
|
content-length: 16
|
|
|
|
content-type: text/plain
|
|
|
|
|
|
|
|
Hello, Alladin!
|
2016-01-14 20:00:50 +01:00
|
|
|
----
|