1
0
mirror of https://github.com/actix/examples synced 2024-11-28 00:12:57 +01:00
examples/auth/cookie-auth/README.md

33 lines
945 B
Markdown
Raw Normal View History

2019-12-18 03:25:06 +01:00
# cookie-auth
```sh
2022-02-18 03:18:44 +01:00
cd auth/cookie-auth
cargo run
# Starting http server: 127.0.0.1:8080
```
2019-12-18 03:25:06 +01:00
Testing with cookie auth with [curl](https://curl.haxx.se).
Login:
curl -v -b "auth-example=user1" -X POST http://localhost:8080/login
< HTTP/1.1 302 Found
< set-cookie: auth-example=GRm2Vku0UpFbJ3CNTKbndzIYHVGi8wc8eoXm/Axtf2BO; HttpOnly; Path=/
< location: /
Uses a POST request with a Useridentity `user1`. A cookie is set and a redirect to home `/` follows.
Get:
Now with the cookie `auth-example` sent in a GET request, the `user1` is recognized.
curl -v -b "auth-example=GRm2Vku0UpFbJ3CNTKbndzIYHVGi8wc8eoXm/Axtf2BO" http://localhost:8080/
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> Cookie: auth-example=GRm2Vku0UpFbJ3CNTKbndzIYHVGi8wc8eoXm/Axtf2BO
2022-03-06 01:43:10 +01:00
>
2019-12-18 03:25:06 +01:00
< HTTP/1.1 200 OK
2022-03-06 01:43:10 +01:00
<
2019-12-18 03:25:06 +01:00
Hello user1