2013-05-10 75 views
2

我正在使用OAuth2Decorator()和Pytgon我正處於那個階段,我仍然不確定關於App Engine的一些事情。文檔沒有提供任何信息,或者我根本無法遵循它。所以:OAuth2Decorator是否存儲用戶憑證並更新令牌?

OAuth2Decorator()存儲用戶Crediantials?

OAuth2Decorator()會自動檢索新令牌嗎?

求索如下例所示:

decorator = OAuth2Decorator(...) 
service = build("drive", "v2") 

class AppHandler(BaseHandler): 
    @decorator.oauth_aware 
    def get(self): 
     if decorator.has_credentials(): 
      init = service.files().list().execute(decorator.http()) 
      items = init['items'] 
      context = {'data': getitems(items)} 
      self.render_response('index.html',**context) 
     else: 
      url = decorator.authorize_url() 
      self.redirect(url) 

回答

3

憑證得到存儲CredentialsModel在數據存儲中。

如果請求的訪問是'離線'(我相信這是默認設置),那麼將在臨時訪問令牌旁邊存儲一個'刷新令牌'。如果使用憑證封裝的Http客戶端發出請求,則在收到指示訪問令牌已過期的響應時,客戶端會自動請求獲取新的訪問令牌,然後重新嘗試原始請求訪問令牌,然後將其存儲在過期的位置。