$ 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
class LogIn: ... def GET( self ): user = require_authenticated_user( self.db ) token = generate_token() self.db.tokens[token] = { "user": user } ...
def GET( self ): ... web.setcookie( "authentication_token", token, expires=36000 # 10 hours ) web.ctx.status = "204 No Content"
def generate_token(): # DO NOT COPY THIS CODE - NOT SECURE return str( random.randint( 0, 1000 ) )
def authenticate_user( db ): authentication_token = web.cookies().get( "authentication_token" ) user_from_token = authenticate_token( db, authentication_token ) if user_from_token is not None: return user_from_token ...
def authenticate_token( db, tok ): if tok is None: return None if tok in db.tokens: return db.tokens[tok]["user"]
Why is this better than passing username and password?
Why is this better than passing username and password?
Videos | youtube.com/user/ajbalaam |
---|---|
@andybalaam | |
Blog | artificialworlds.net/blog |
Projects | artificialworlds.net |