Authenticate an API key against our database
    :param api_key:
    :return: authenticated username
178217
def authenticate_key(api_key):
    
    user_model = Query()
    user = db.search(user_model.api_key == api_key)[0]
    if user:
        return user['username']
    return False
1017634
def authDomainUser(self, realmname, username, password, environ):
        """"""
        try:
            apikey = self.user_manager.get_user_api_key(username, create=None)
            return apikey is not None and password == apikey
        except:
            return False
349540
def api_key(self, api_key):
        
        if api_key is None:
            raise ValueError("Invalid value for `api_key`, must not be `None`")
        if api_key is not None and len(api_key) > 1000:
            raise ValueError("Invalid value for `api_key`, length must be less than or equal to `1000`")

        self._api_key = api_key
1367709
def auth_token(self, apikey=None, secret=None, email=None, password=None):
        
        if (apikey and secret) or (self._apikey and self._secret):
            body = {
                "key_id": apikey or self._apikey,
                "secret": secret or self._secret
            }
        elif (email and password) or (self._email and self._password):
            body = {
                "user" : email or self._email,
                "password" : password or self._password
            }
        else:
            raise Value("No authentication provided.")
        response = self._post(url.auth, body=body)

        self._check_response(response, 200)
        return self._create_response(response).get("jwt")
1076931
def _auth(self):
        
        ts = datetime.datetime.now().strftime("%Y-%m-%d%H:%M:%S")
        hash_string = hashlib.md5("%s%s%s" % (ts, self.private_key, self.public_key)).hexdigest()
        return "ts=%s&apikey=%s&hash=%s" % (ts, self.public_key, hash_string)
1356698
def __get_auth(self):
        ''''''
        if self.api_key == None and self.login == None:
            self.logger.error("No authentication provided! Unable to connect.")
            sys.exit(1)

        if self.api_key == None:
            self.logger.info("Authenticating with email/password.")
            return [
                "email: " + self.login,
                "password: " + self.password
            ]
        else:
            self.logger.info("Authenticating with API Key.")
            # To auth to the WS using an API key, we generate a signature of a nonce and
            # the WS API endpoint.
            nonce = generate_nonce()
            return [
                "api-nonce: " + str(nonce),
                "api-signature: " + generate_signature(self.api_secret, 'GET', '/realtime', nonce, ''),
                "api-key:" + self.api_key
            ]
428173
def _get_api_key_ops():
    """"""
    auth_header = request.authorization
    if not auth_header:
        logging.debug('API request lacks authorization header')
        abort(flask.Response(
            'API key required', 401,
            {'WWW-Authenticate': 'Basic realm="API key required"'}))

    return operations.ApiKeyOps(auth_header.username, auth_header.password)
84314
def authenticate_user(self, request, user):
        
        return user.check_password(request.data.get('password')) or \
               self.check_user_token(request, user)
6534
def find_by_id(key: str, user: str=None) -> Optional['ApiKey']:
        
        return ApiKey.from_db(db.get_key(key, user))
254405
def getRealmUserPassword(self, realmname, username, environ):
        
        return self.user_manager.get_user_api_key(username, create=True)
1187881
def authenticate_identify(self, api_token, override=True):
        
        if (self.context.has_auth_params('Gem-Identify') and not override):
            raise OverrideError('Gem-Identify')

        if (not api_token or
            not self.context.authorize('Gem-Identify', api_token=api_token)):
            raise AuthUsageError(self.context, 'Gem-Identify')

        return True
930656
def get_api_key(self, api_key_id):
        
        api = self._get_api(iam.DeveloperApi)
        return ApiKey(api.get_api_key(api_key_id))
176353
def login_uname_pwd(server, api_key=None):
    
    username = click.prompt("Please enter your One Codex (email)")
    if api_key is not None:
        return username, api_key

    password = click.prompt("Please enter your password (typing will be hidden)", hide_input=True)

    # now get the API key
    api_key = fetch_api_key_from_uname(username, password, server)
    return username, api_key
1141688
def fetch_api_key_from_uname(username, password, server_url):
    
    # TODO: Hit programmatic endpoint to fetch JWT key, not API key
    with requests.Session() as session:
        # get the login page normally
        text = session.get(server_url + "login").text

        # retrieve the CSRF token out of it
        csrf = re.search('type="hidden" value="([^"]+)"', text).group(1)

        # and resubmit using the username/password *and* the CSRF
        login_data = {
            "email": username,
            "password": password,
            "csrf_token": csrf,
            "next": "/api/get_token",
        }
        page = session.post(server_url + "login", data=login_data)
        try:
            key = page.json()["key"]
        except (ValueError, KeyError):  # ValueError includes simplejson.decoder.JSONDecodeError
            key = None
    return key
271010
def describe_api_keys(region=None, key=None, keyid=None, profile=None):
    '''
    

    '''
    try:
        conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
        apikeys = _multi_call(conn.get_api_keys, 'items')

        return {'apiKeys': [_convert_datetime_str(apikey) for apikey in apikeys]}
    except ClientError as e:
        return {'error': __utils__['boto3.get_error'](e)}
1086942
def get_user(self, key = None):
		'''
		''' 	
		if key:
			uri = self.api_uri + "/users/" + key
		else:
			uri = self.api_uri + "/users/me"

		return self._req('get', uri)
149751
def tvdb_login(api_key):
    
    url = "https://api.thetvdb.com/login"
    body = {"apikey": api_key}
    status, content = _request_json(url, body=body, cache=False)
    if status == 401:
        raise MapiProviderException("invalid api key")
    elif status != 200 or not content.get("token"):
        raise MapiNetworkException("TVDb down or unavailable?")
    return content["token"]