def load_user_from_request(request): api_key = request.args.get('api_key') if api_key and len(api_key): account = Account.by_api_key(api_key) if account: return account api_key = request.headers.get('Authorization') if api_key and len(api_key) and ' ' in api_key: method, api_key = api_key.split(' ', 1) if method.lower() == 'apikey': account = Account.by_api_key(api_key) if account: return account return None
def authenticate(self, environ, identity): """ Try to authenticate user based on api key identity """ # If identity has apikey we get the account by the api key # and return none if no account or apikey is found is found if 'apikey' in identity: acc = Account.by_api_key(identity.get('apikey')) if acc is not None: return acc.name return None