2014-05-12 34 views
1

我有我的django rest框架API受Oauth2工具包保護,但我不知道如何獲得當前授權請求的client_id如何在django rest框架中訪問OAuth2 client_id?

class RequestTransactionView(APIView): 

    def post(self, request, format=None): 
     transaction = self.parse_dictionary(request.DATA) 
     return Response(str(transaction.goid)) 

我已檢查了request對象,這給:

['DATA', 'FILES', 'QUERY_PARAMS', '_CONTENTTYPE_PARAM', '_CONTENT_PARAM', '_METHOD_PARAM', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_auth', '_authenticate', '_authenticator', '_content_type', '_data', '_default_negotiator', '_files', '_load_data_and_files', '_load_method_and_content_type', '_load_stream', '_method', '_not_authenticated', '_parse', '_perform_form_overloading', '_request', '_stream', '_user', 'accepted_media_type', 'accepted_renderer', 'auth', 'authenticators', 'content_type', 'method', 'negotiator', 'parser_context', 'parsers', 'stream', 'successful_authenticator', 'user'] 

然後我檢查了successful_authenticator我:

['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'authenticate', 'authenticate_header', 'www_authenticate_realm'] 

我還考察了其他明顯的提示,但沒有運氣。

回答

1

當我打印時比我想象的要容易request.auth我得到一個字符串,我認爲它是一個字符串類型,但後來我發現它是一個AccessToken,所以從那裏我可以直接獲取應用程序。

print request.auth.application