python/dna/apy/auth.py
def requires_token_auth(resource):
    '''
    Flask decorator protecting ressources using token scheme
    '''
    @functools.wraps(resource)
    def decorated(*args, **kwargs):
        ''' Check provided token '''
        token = flask.request.headers.get('Authorization')
        user = check_token(token)

        if not token or user is None:
            log.warn('authentification failed', token=token)
            return auth_failed()

        flask.g.user = user
        log.info('authentification succeeded', token=token, user=flask.g.user)
        return resource(*args, **kwargs)
    return decorated
def requires_token_auth(resource):
    '''
    Flask decorator protecting ressources using token scheme
    '''
    @functools.wraps(resource)
    def decorated(*args, **kwargs):
        ''' Check provided token '''
        token = flask.request.headers.get('Authorization')
        user = check_token(token)

        if not token or user is None:
            log.warn('authentification failed', token=token)
            return auth_failed()

        flask.g.user = user
        log.info('authentification succeeded', token=token, user=flask.g.user)
        return resource(*args, **kwargs)
    return decorated
Flask decorator protecting ressources using token scheme