2014-05-12 35 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