Example #1
0
  def authErrors():
    # Check auth
    if not request.headers.get('Authorization'):
      return ({'status': 'error', 'reason': 'Authentication needed'}, 401)
    method, name, token = Advanced_API.getAuth()

    data = None
    if method.lower() not in ['basic', 'token', 'session', 'bearer']:
      data = ({'status': 'error', 'reason': 'Authorization method not allowed'}, 400)
    else:
      try:
        authenticated = False
        if   method.lower() == 'basic':
          authenticator = AuthenticationHandler()
          if authenticator.validateUser(name, token): authenticated = True
        elif method.lower() == 'bearer':
            authenticated, name  = db.isBearerAuthenticated(token)
        elif method.lower() == 'token':
            if db.getToken(name) == token: authenticated = True
        elif method.lower() == 'session':
          authenticator = AuthenticationHandler()
          if authenticator.api_sessions.get(name) == token: authenticated = True
        if not authenticated: data = ({'status': 'error', 'reason': 'Authentication failed'}, 401)
      except Exception as e:
        print(e)
        data = ({'status': 'error', 'reason': 'Malformed Authentication String'}, 400)
    if data:
      return data
    else: return None
Example #2
0
 def authErrors():
   # Check auth
   if not request.headers.get('Authorization'):
     return ({'status': 'error', 'reason': 'Authentication needed'}, 401)
   method, name, token = Advanced_API.getAuth()
   data = None
   if method.lower() not in ['basic', 'token', 'session']:
     data = ({'status': 'error', 'reason': 'Authorization method not allowed'}, 400)
   else:
     try:
       authenticated = False
       if   method.lower() == 'basic':
         authenticator = AuthenticationHandler()
         if authenticator.validateUser(name, token): authenticated = True
       elif method.lower() == 'token':
         if db.getToken(name) == token: authenticated = True
       elif method.lower() == 'session':
         authenticator = AuthenticationHandler()
         if authenticator.api_sessions.get(name) == token: authenticated = True
       if not authenticated: data = ({'status': 'error', 'reason': 'Authentication failed'}, 401)
     except Exception as e:
       print(e)
       data = ({'status': 'error', 'reason': 'Malformed Authentication String'}, 400)
   if data:
     return data
   else: return None
Example #3
0
 def authErrors(self):
     # Check auth
     if not request.headers.get("Authorization"):
         return ({
             "status": "error",
             "reason": "Authentication needed"
         }, 401)
     method, name, token = Advanced_API.getAuth()
     data = None
     if method.lower() not in ["basic", "token", "session"]:
         data = (
             {
                 "status": "error",
                 "reason": "Authorization method not allowed"
             },
             400,
         )
     else:
         try:
             authenticated = False
             if method.lower() == "basic":
                 authenticator = AuthenticationHandler()
                 if authenticator.validateUser(name, token):
                     authenticated = True
             elif method.lower() == "token":
                 if db.getToken(name) == token:
                     authenticated = True
             elif method.lower() == "session":
                 authenticator = AuthenticationHandler()
                 if authenticator.api_sessions.get(name) == token:
                     authenticated = True
             if not authenticated:
                 data = ({
                     "status": "error",
                     "reason": "Authentication failed"
                 }, 401)
         except Exception as e:
             print(e)
             data = (
                 {
                     "status": "error",
                     "reason": "Malformed Authentication String"
                 },
                 400,
             )
     if data:
         return data
     else:
         return None
Example #4
0
 def authErrors():
     db = DatabaseLayer(
     )  # Required to circumvent the use of self, because of this being a wrapper (This is one reason to use a singleton ;) )
     # Check auth
     if not request.headers.get('Authorization'):
         return ({
             'status': 'error',
             'reason': 'Authentication needed'
         }, 401)
     method, name, token = Advanced_API.getAuth()
     data = None
     if method.lower() not in ['basic', 'token', 'session']:
         data = ({
             'status': 'error',
             'reason': 'Authorization method not allowed'
         }, 400)
     else:
         try:
             authenticated = False
             if method.lower() == 'basic':
                 authenticator = AuthenticationHandler()
                 if authenticator.validateUser(name, token):
                     authenticated = True
             elif method.lower() == 'token':
                 if db.Users.getToken(name) == token: authenticated = True
             elif method.lower() == 'session':
                 authenticator = AuthenticationHandler()
                 if authenticator.api_sessions.get(name) == token:
                     authenticated = True
             if not authenticated:
                 data = ({
                     'status': 'error',
                     'reason': 'Authentication failed'
                 }, 401)
         except Exception as e:
             print(e)
             data = ({
                 'status': 'error',
                 'reason': 'Malformed Authentication String'
             }, 400)
     if data:
         return data
     else:
         return None