在restful中基于token的认证

用户只登录一次
下次访问的时候使用cookie而不是username或者是密码

失效

1
2
3
4
5
6
7
curl -c c.txt 
http://localhost:8080/api/v1/login
-u user1:pass1

curl -b c.txt
--data '{titl...}'
http://localhost:8080/api/v1/poems

logging in

1
2
3
4
5
def GET(self):
user = require_authenticated_user(
self.db)
token = generate_token()
self.db.tokens[tooken] = {"user": user}