示例#1
0
    def _get_user_for_apikey(self, environ):
        '''
        Attempt to find a CKAN user from potential API key provided in environ object
        :param environ:
        :return: user object or None
        '''
        apikey_header_name = config.get(base.APIKEY_HEADER_NAME_KEY,
                                        base.APIKEY_HEADER_NAME_DEFAULT)
        apikey = environ.get(apikey_header_name, '')
        if not apikey:
            # For misunderstanding old documentation (now fixed).
            apikey = environ.get(u'HTTP_AUTHORIZATION', u'')
        if not apikey:
            apikey = environ.get(u'Authorization', u'')
            # Forget HTTP Auth credentials (they have spaces).
            if u' ' in apikey:
                apikey = u''
        if not apikey:
            return None
        apikey = six.ensure_text(apikey, errors=u"ignore")
        query = model.Session.query(model.User)
        user = query.filter_by(apikey=apikey).first()

        if not user:
            user = api_token.get_user_from_token(apikey)
        return user
    def _get_user_for_apikey(self, environ):
        # Based off method _get_user_for_apikey from https://github.com/ckan/ckan/blob/afe077e78e929a38112980d24df7c5d057b363ec/ckan/views/__init__.py
        # Updated to remove request and use paramater environ
        apikey_header_name = toolkit.config.get(views.APIKEY_HEADER_NAME_KEY,
                                                views.APIKEY_HEADER_NAME_DEFAULT)
        apikey = environ.get(apikey_header_name, u'')
        if not apikey:
            # For misunderstanding old documentation (now fixed).
            apikey = environ.get(u'HTTP_AUTHORIZATION', u'')
        if not apikey:
            apikey = environ.get(u'Authorization', u'')
            # Forget HTTP Auth credentials (they have spaces).
            if u' ' in apikey:
                apikey = u''

        if not apikey:
            return None

        apikey = six.ensure_text(apikey, errors=u"ignore")
        query = model.Session.query(model.User)
        user = query.filter_by(apikey=apikey).first()

        if not user:
            user = api_token.get_user_from_token(apikey)

        return user
示例#3
0
文件: __init__.py 项目: detanxx/ckan
def _get_user_for_apitoken() -> Optional[model.User]:
    apitoken_header_name = config.get_value("apikey_header_name")

    apitoken: str = request.headers.get(apitoken_header_name, u'')
    if not apitoken:
        apitoken = request.environ.get(apitoken_header_name, u'')
    if not apitoken:
        # For misunderstanding old documentation (now fixed).
        apitoken = request.environ.get(u'HTTP_AUTHORIZATION', u'')
    if not apitoken:
        apitoken = request.environ.get(u'Authorization', u'')
        # Forget HTTP Auth credentials (they have spaces).
        if u' ' in apitoken:
            apitoken = u''
    if not apitoken:
        return None
    apitoken = six.ensure_text(apitoken, errors=u"ignore")
    log.debug(u'Received API Token: %s' % apitoken)

    user = api_token.get_user_from_token(apitoken)

    return user
示例#4
0
def _get_user_for_apikey():
    apikey_header_name = config.get(APIKEY_HEADER_NAME_KEY,
                                    APIKEY_HEADER_NAME_DEFAULT)
    apikey = request.headers.get(apikey_header_name, u'')
    if not apikey:
        apikey = request.environ.get(apikey_header_name, u'')
    if not apikey:
        # For misunderstanding old documentation (now fixed).
        apikey = request.environ.get(u'HTTP_AUTHORIZATION', u'')
    if not apikey:
        apikey = request.environ.get(u'Authorization', u'')
        # Forget HTTP Auth credentials (they have spaces).
        if u' ' in apikey:
            apikey = u''
    if not apikey:
        return None
    apikey = six.ensure_text(apikey, errors=u"ignore")
    log.debug(u'Received API Key: %s' % apikey)
    query = model.Session.query(model.User)
    user = query.filter_by(apikey=apikey).first()

    if not user:
        user = api_token.get_user_from_token(apikey)
    return user