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

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 ) : 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 ) : 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 .