0
我很努力地使用django檢索訪問令牌。 我想從使用oAuth的用戶獲取訪問令牌。Google OAUTH使用django獲取訪問令牌
這是我到目前爲止設置的。
class GoogleExhangeViewSet(viewsets.ViewSet):
queryset = User.objects.all()
@list_route(
methods=["GET"])
def auth(self,request,pk=None):
client_id = ''
client_secret = ''
flow = OAuth2WebServerFlow(client_id=client_id,
client_secret=client_secret,
scope='https://www.googleapis.com/auth/calendar',
redirect_uri='http://localhost:8001/api/googleAuth/complete')
auth_uri = flow.step1_get_authorize_url()
return HttpResponseRedirect(auth_uri)
def complete(self, request, pk=None):
client_id = ''
client_secret = ''
host = Site.objects.get_current().name
flow = OAuth2WebServerFlow(client_id=client_id,
client_secret=client_secret,
scope='https://www.googleapis.com/auth/calendar',
redirect_uri='http://localhost')
credentials = flow.step2_exchange(request.GET.get('code'))
return Response(status=200,data=credentials.access_token)
下urls.py我
api_router.register(r'api/googleAuth', GoogleExhangeViewSet)