Return an ApiAuth instance from an encoded key
181137
def get_instance(cls, encoded_key):
        

        login_str = base64.b64decode(encoded_key).decode('utf-8')
        usertoken, password = login_str.strip().split(':', 1)

        instance = cls(usertoken, password)

        return instance
1123680
def _require_authenticate(func):
    ''''''

    def wrapped(self):
        if not hasattr(self, 'authenticated'):
            self.authenticated = None
        if self.authenticated:
            return func(self)

        auth = self.headers.get(u'Authorization')
        if auth is None:
            msg = u"You are not allowed to access this page. Please login first!"
            return _error_401(self, msg)

        token, fields = auth.split(' ', 1)
        if token != 'Digest':
            return _error_401(self, 'Unsupported authentication type')

        # Check the header fields of the request.
        cred = parse_http_list(fields)
        cred = parse_keqv_list(cred)
        keys = u'realm', u'username', u'nonce', u'uri', u'response'
        if not all(cred.get(key) for key in keys):
            return _error_401(self, 'Incomplete authentication header')
        if cred['realm'] != self.server.realm:
            return _error_401(self, 'Incorrect realm')
        if 'qop' in cred and ('nc' not in cred or 'cnonce' not in cred):
            return _error_401(self, 'qop with missing nc or cnonce')

        # Check the username.
        username = cred['username']
        password = self.server.get_password(username)
        if not username or password is None:
            return _error_401(self, 'Invalid username or password')

        # Check the digest string.
        location = u'%s:%s' % (self.command, self.path)
        location = md5hex(location.encode('utf8'))
        pwhash = md5hex('%s:%s:%s' % (username, self.server.realm, password))

        if 'qop' in cred:
            info = (cred['nonce'],
                    cred['nc'],
                    cred['cnonce'],
                    cred['qop'],
                    location)
        else:
            info = cred['nonce'], location

        expect = u'%s:%s' % (pwhash, ':'.join(info))
        expect = md5hex(expect.encode('utf8'))
        if expect != cred['response']:
            return _error_401(self, 'Invalid username or password')

        # Success!
        self.authenticated = True
        return func(self)

    return wrapped
651228
def _api_get(self, url, **kwargs):
        
        kwargs['url'] = self.url + url
        kwargs['auth'] = self.auth

        headers = deepcopy(self.headers)
        headers.update(kwargs.get('headers', {}))
        kwargs['headers'] = headers
        return self._get(**kwargs)
369433
def hkeys(self, key, *, encoding=_NOTSET):
        """"""
        return self.execute(b'HKEYS', key, encoding=encoding)
966165
def get(key, opts = {})
      response = api_execute(key_endpoint + key, :get, params: opts)
      Response.from_http_response(response)
    end
357374
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
    {
        return uc_authcode($string, $operation, $key, $expiry);
    }
279713
function hkeys(key, req) {
  var val = this.getKey(key, req);
  if(!val) return [];
  return val.getKeys();
}
1216087
function hmac(key, string, encoding) {
  return crypto.createHmac('sha256', key).update(string, 'utf8').digest(encoding)
}
1001568
def create_authentication_from_json(values):
        """"""
        key_id = values.get('publicKey')
        authentication_type = values.get('type')
        if not key_id:
            raise ValueError(
                f'Invalid authentication definition, "publicKey" is missing: {values}')

        authentication = {'type': authentication_type, 'publicKey': key_id}

        return authentication
992100
def get_from_params(request, key):
    
    data = getattr(request, 'json', None) or request.values
    value = data.get(key)
    return to_native(value)
579915
def from_dict(cls, data):
        
        auth_info = AuthenticationInformation.from_dict(
            data.get("auth_info", {})
        )
        instance = cls(
            auth_info=auth_info,
            requester=data.get("requester"),
            requester_name=data.get("requester_name"),
            subject_id=data.get("subject_id"),
            subject_type=data.get("subject_type"),
            attributes=data.get("attributes"),
            user_id=data.get("user_id"),
            user_id_hash_type=data.get("hash_type"),
            name_id=data.get("name_id"),
            approved_attributes=data.get("approved_attributes"),
        )
        return instance
606253
def get_api_user_key(self, api_dev_key, username=None, password=None):
        '''
        
        '''
        username = username or get_config('pastebin', 'api_user_name')
        password = password or get_config('pastebin', 'api_user_password')
        if username and password:
            data = {
                'api_user_name': username,
                'api_user_password': password,
                'api_dev_key': api_dev_key,
            }
            urlencoded_data = urllib.urlencode(data)
            req = urllib2.Request('http://pastebin.com/api/api_login.php',
                                  urlencoded_data)
            response = urllib2.urlopen(req)
            user_key = response.read()
            logging.debug("User key: %s" % user_key)
            return user_key
        else:
            logging.info("Pastebin: not using any user key")
            return ""
873498
def get_request(self, request):
        """"""
        request.headers['authenticate'] = {
            'username': self.username,
            'apiKey': self.api_key,
        }
        return request
540182
def from_url(cls, url: URL,
                 *, encoding: str='latin1') -> Optional['BasicAuth']:
        """"""
        if not isinstance(url, URL):
            raise TypeError("url should be yarl.URL instance")
        if url.user is None:
            return None
        return cls(url.user, url.password or '', encoding=encoding)
193101
def from_dict(cls, data):
        
        auth_info = _AuthenticationInformation.from_dict(data.get("auth_info"))
        instance = cls(auth_info=auth_info)
        instance.user_id_hash_type = data.get("hash_type")
        instance.attributes = data.get("attributes", {})
        instance.user_id = data.get("user_id")
        instance.requester = data.get("requester")
        return instance
815615
def _JsonDecodeKey(d):
    """"""
    k_c = d['key_string']
    if isinstance(k_c, (list, tuple)):
        return ndb.Key(flat=k_c)
    return ndb.Key(urlsafe=d['key_string'])
706236
def decode_token(self, token):
        """"""
        key = current_app.secret_key
        if key is None:
            if current_app.debug:
                current_app.logger.debug("app.secret_key not set")
            return None
        try:
            return jwt.decode(
                token, key,
                algorithms=[self.config["algorithm"]],
                options={'require_exp': True}
            )
        except jwt.InvalidTokenError:
            return None