flask_oauthlib/contrib/oauth2.py
def bind_cache_grant(app, provider, current_user, config_prefix='OAUTH2'):
    """Configures an :class:`OAuth2Provider` instance to use various caching
    systems to get and set the grant token. This removes the need to
    register :func:`grantgetter` and :func:`grantsetter` yourself.

    :param app: Flask application instance
    :param provider: :class:`OAuth2Provider` instance
    :param current_user: function that returns an :class:`User` object
    :param config_prefix: prefix for config

    A usage example::

        oauth = OAuth2Provider(app)
        app.config.update({'OAUTH2_CACHE_TYPE': 'redis'})

        bind_cache_grant(app, oauth, current_user)

    You can define which cache system you would like to use by setting the
    following configuration option::

        OAUTH2_CACHE_TYPE = 'null' // memcache, simple, redis, filesystem

    For more information on the supported cache systems please visit:
    `Cache <http://werkzeug.pocoo.org/docs/contrib/cache/>`_
    """
    cache = Cache(app, config_prefix)

    @provider.grantsetter
    def create_grant(client_id, code, request, *args, **kwargs):
        """Sets the grant token with the configured cache system"""
        grant = Grant(
            cache,
            client_id=client_id,
            code=code['code'],
            redirect_uri=request.redirect_uri,
            scopes=request.scopes,
            user=current_user(),
        )
        log.debug("Set Grant Token with key %s" % grant.key)
        cache.set(grant.key, dict(grant))

    @provider.grantgetter
    def get(client_id, code):
        """Gets the grant token with the configured cache system"""
        grant = Grant(cache, client_id=client_id, code=code)
        ret = cache.get(grant.key)
        if not ret:
            log.debug("Grant Token not found with key %s" % grant.key)
            return None
        log.debug("Grant Token found with key %s" % grant.key)
        for k, v in ret.items():
            setattr(grant, k, v)
        return grant
def bind_cache_grant(app, provider, current_user, config_prefix='OAUTH2'):
    """Configures an :class:`OAuth2Provider` instance to use various caching
    systems to get and set the grant token. This removes the need to
    register :func:`grantgetter` and :func:`grantsetter` yourself.

    :param app: Flask application instance
    :param provider: :class:`OAuth2Provider` instance
    :param current_user: function that returns an :class:`User` object
    :param config_prefix: prefix for config

    A usage example::

        oauth = OAuth2Provider(app)
        app.config.update({'OAUTH2_CACHE_TYPE': 'redis'})

        bind_cache_grant(app, oauth, current_user)

    You can define which cache system you would like to use by setting the
    following configuration option::

        OAUTH2_CACHE_TYPE = 'null' // memcache, simple, redis, filesystem

    For more information on the supported cache systems please visit:
    `Cache <http://werkzeug.pocoo.org/docs/contrib/cache/>`_
    """
    cache = Cache(app, config_prefix)

    @provider.grantsetter
    def create_grant(client_id, code, request, *args, **kwargs):
        """Sets the grant token with the configured cache system"""
        grant = Grant(
            cache,
            client_id=client_id,
            code=code['code'],
            redirect_uri=request.redirect_uri,
            scopes=request.scopes,
            user=current_user(),
        )
        log.debug("Set Grant Token with key %s" % grant.key)
        cache.set(grant.key, dict(grant))

    @provider.grantgetter
    def get(client_id, code):
        """Gets the grant token with the configured cache system"""
        grant = Grant(cache, client_id=client_id, code=code)
        ret = cache.get(grant.key)
        if not ret:
            log.debug("Grant Token not found with key %s" % grant.key)
            return None
        log.debug("Grant Token found with key %s" % grant.key)
        for k, v in ret.items():
            setattr(grant, k, v)
        return grant
def bind_cache_grant ( app , provider , current_user , config_prefix = 'OAUTH2' ) : cache = Cache ( app , config_prefix ) @ provider . grantsetter def create_grant ( client_id , code , request , * args , * * kwargs ) : """Sets the grant token with the configured cache system""" grant = Grant ( cache , client_id = client_id , code = code [ 'code' ] , redirect_uri = request . redirect_uri , scopes = request . scopes , user = current_user ( ) , ) log . debug ( "Set Grant Token with key %s" % grant . key ) cache . set ( grant . key , dict ( grant ) ) @ provider . grantgetter def get ( client_id , code ) : """Gets the grant token with the configured cache system""" grant = Grant ( cache , client_id = client_id , code = code ) ret = cache . get ( grant . key ) if not ret : log . debug ( "Grant Token not found with key %s" % grant . key ) return None log . debug ( "Grant Token found with key %s" % grant . key ) for k , v in ret . items ( ) : setattr ( grant , k , v ) return grant
Configures an :class:`OAuth2Provider` instance to use various caching
    systems to get and set the grant token. This removes the need to
    register :func:`grantgetter` and :func:`grantsetter` yourself.

    :param app: Flask application instance
    :param provider: :class:`OAuth2Provider` instance
    :param current_user: function that returns an :class:`User` object
    :param config_prefix: prefix for config

    A usage example::

        oauth = OAuth2Provider(app)
        app.config.update({'OAUTH2_CACHE_TYPE': 'redis'})

        bind_cache_grant(app, oauth, current_user)

    You can define which cache system you would like to use by setting the
    following configuration option::

        OAUTH2_CACHE_TYPE = 'null' // memcache, simple, redis, filesystem

    For more information on the supported cache systems please visit:
    `Cache <http://werkzeug.pocoo.org/docs/contrib/cache/>`_
Configures an : class : OAuth2Provider instance to use various caching systems to get and set the grant token . This removes the need to register : func : grantgetter and : func : grantsetter yourself .