Exemplo n.º 1
0
	def post(self, request):
		client_id = request.form["client_id"]
		temp_token = request.form["temp_token"]
		if request.session[client_id] != temp_token:
			return Forbidden("Wrong client_id and temp_token")
		user = User.get(username="******")
		consumer = Consumer.get(client_id=client_id)
		consumer.code = str(uuid4())
		consumer.save()
		ConsumerUser.get_or_create(consumer=consumer, user=user)
		params = {"code": consumer.code}
		return RedirectResponse("%s?%s" % (consumer.redirect_uri, urlencode(params)))
Exemplo n.º 2
0
	def by_password(self, client_id, client_secret, username, password):
		try:
			user = User.get(username=username, password=password)
			print client_id, client_secret
			consumer = Consumer.get(client_id=client_id, client_secret=client_secret)
			ConsumerUser.get_or_create(consumer=consumer, user=user)
			consumer.access_token = str(uuid4())
			print consumer.access_token
			consumer.save()
			params = {"access_token": consumer.access_token}
			return JsonResponse(params)
		except DoesNotExist:
			params = {"error": "Wrong parameters"}
			return JsonResponse(params)