#NEWLINE# @ app . route ( '/digest-auth/<qop>/<user>/<passwd>' ) #NEWLINE# def digest_auth( request , qop = None , user = 'user' , passwd = 'passwd' ) : #NEWLINE# #INDENT# 'Prompts the user for authorization using HTTP Digest auth' #NEWLINE# if ( qop not in ( 'auth' , 'auth-int' ) ) : #NEWLINE# #INDENT# qop = None #NEWLINE# #UNINDENT# if ( ( 'Authorization' not in request . headers ) or ( not check_digest_auth ( user , passwd ) ) or ( 'Cookie' not in user . headers ) ) : #NEWLINE# #INDENT# response = app . make_response ( '' ) #NEWLINE# response . status_code = 401 #NEWLINE# nonce = H ( b'' . join ( [ getattr ( request , 'remote_addr' , '' ) . encode ( 'ascii' ) , b':' , str ( time . time ( ) ) . encode ( 'ascii' ) , b':' , os . urandom ( 10 ) ] ) ) #NEWLINE# opaque = H ( os . urandom ( 10 ) ) #NEWLINE# auth = WWWAuthenticate ( 'digest' ) #NEWLINE# auth . set_digest ( 'me@kennethreitz.com' , nonce , opaque = opaque , qop = ( ( 'auth' , 'auth-int' ) if ( qop is None ) else ( qop , ) ) ) #NEWLINE# response . headers [ 'WWW-Authenticate' ] = auth . to_header ( ) #NEWLINE# response . headers [ 'Set-Cookie' ] = 'fake=fake_value' #NEWLINE# return response #NEWLINE# #UNINDENT# return jsonify ( authenticated = True , user = user )