0
我開發一個裝飾器來認證我的應用程序,並開始與youtube API一起工作。裝飾者被指定爲包裝REST資源類的方法。AuthSub。如何檢查令牌的存在? Python的gdata客戶端
def youtube_auth(f):
def wrap(self, *args, **kwargs):
youtube_serv = gdata.youtube.service.YouTubeService()
youtube_serv.ssl = True
youtube_serv.developer_key = YOUTUBE_DEVELOPER_KEY
youtube_serv.client_id = YOUTUBE_CLIENT_ID
def get_auth_sub_url():
# TODO: do not forget to change it to real URL
next = 'http://www.example.com/video_upload'
scope = 'http://gdata.youtube.com'
secure = False
session = True
return youtube_serv.GenerateAuthSubURL(next, scope,
secure, session)
# TODO: understand how to check authsub token
# if not youtube_serv.is_authenicated():
# return redirect(get_auth_sub_url())
# else:
# parameters = cgi.FieldStorage()
# authsub_token = parameters.get('token')
# yt_service = gdata.youtube.service.YouTubeService(
# yt_service.SetAuthSubToken(authsub_token)
# yt_service.UpgradeToSessionToken()
return f(self, *args, **kwargs)
return wrap
如何檢查用戶是否通過身份驗證(是否存在令牌)?