def authenticated_client_from_request(_db, required=True): header = request.headers.get('Authorization') if header and 'bearer' in header.lower(): shared_secret = base64.b64decode(header.split(' ')[1]) client = IntegrationClient.authenticate(_db, shared_secret) if client: return client if not required and not header: # In the case that authentication is not required # (i.e. URN lookup) return None instead of an error. return None return INVALID_CREDENTIALS
def authenticated_client_from_request(_db, required=True): header = request.authorization if header: key, secret = header.username, header.password client = IntegrationClient.authenticate(_db, key, secret) if client: return client if not required and not header: # In the case that authentication is not required # (i.e. URN lookup) return None instead of an error. return None return INVALID_CREDENTIALS