@asyncio.coroutine
def auth_middleware(app, handler):
 if (app['hass'].http.api_password is None):
  @asyncio.coroutine
  def no_auth_middleware_handler(request):
   'Auth middleware to approve all requests.'
   request[KEY_AUTHENTICATED] = True
   return handler(request)
  return no_auth_middleware_handler
 @asyncio.coroutine
 def auth_middleware_handler(request):
  'Auth middleware to check authentication.'
  authenticated = False
  if ((HTTP_HEADER_HA_AUTH in request.headers) and validate_password(request, request.headers[HTTP_HEADER_HA_AUTH])):
   authenticated = True
  elif ((DATA_API_PASSWORD in request.GET) and validate_password(request, request.GET[DATA_API_PASSWORD])):
   authenticated = True
  elif is_trusted_ip(request):
   authenticated = True
  request[KEY_AUTHENTICATED] = authenticated
  return handler(request)
 return auth_middleware_handler

@ asyncio . coroutine def auth_middleware ( app , handler ) : if ( app [ 'hass' ] . http . api_password is None ) : @ asyncio . coroutine def no_auth_middleware_handler ( request ) : request [ KEY_AUTHENTICATED ] = True return handler ( request ) return no_auth_middleware_handler @ asyncio . coroutine def auth_middleware_handler ( request ) : authenticated = False if ( ( HTTP_HEADER_HA_AUTH in request . headers ) and validate_password ( request , request . headers [ HTTP_HEADER_HA_AUTH ] ) ) : authenticated = True elif ( ( DATA_API_PASSWORD in request . GET ) and validate_password ( request , request . GET [ DATA_API_PASSWORD ] ) ) : authenticated = True elif is_trusted_ip ( request ) : authenticated = True request [ KEY_AUTHENTICATED ] = authenticated return handler ( request ) return auth_middleware_handler
authentication middleware .