소스 검색

Basic auth test

Hal De 4 년 전
부모
커밋
e463209b83
1개의 변경된 파일4개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      app/app.py

+ 4 - 0
app/app.py

@@ -134,11 +134,15 @@ def authRequired(func):
   @wraps(func)
   async def authWrapper(*args, **kwargs):
     auth = request.authorization
+    headers = request.headers
     if ((auth is not None) and
         (auth.type == "basic") and
         (auth.username in current_app.cache['devices']) and
         (compare_digest(auth.password, current_app.cache['devices'][auth.username]))):
       return await func(*args, **kwargs)
+    else if ((current_app.config['AUTH_HEADER'].lower() in headers) and
+             (headers[current_app.config['AUTH_HEADER'].lower()] == current_app.config['AUTH_SECRET'])):
+      return await func(*args, **kwargs)
     else:
       abort(401)
   return authWrapper